File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -193,14 +193,8 @@ class ImageCache {
193193 _cache[key] = image;
194194 return image.completer;
195195 }
196- if (result != null ) {
197- return result;
198- }
199196 try {
200197 result = loader ();
201- if (result == null ) {
202- return null ;
203- }
204198 } catch (error, stackTrace) {
205199 if (onError != null ) {
206200 onError (error, stackTrace);
Original file line number Diff line number Diff line change @@ -281,9 +281,15 @@ abstract class ImageProvider<T> {
281281 return stream;
282282 }
283283
284+ /// This method does the acutal work of [resolve] , both decoding the image
285+ /// and making sure it ends up in the [ImageCache] .
286+ ///
284287 /// Subclasses that need to manage resolution more finely should override
285288 /// this method, which is called by [resolve] with the [ImageStream] that gets
286- /// returned to callers of [resolve] .
289+ /// returned to callers of [resolve] . For example, the
290+ /// [DeferringImageProvider] overrides this method to give callers time to
291+ /// either cancel or continue based on a condition before actually decoding
292+ /// and caching the image.
287293 @protected
288294 void resolveForStream (ImageConfiguration configuration, ImageStream stream) {
289295 assert (configuration != null );
Original file line number Diff line number Diff line change @@ -1017,10 +1017,16 @@ class _ImageState extends State<Image> with WidgetsBindingObserver {
10171017 // Is it scrolling so fast that the image is unlikely stay around long
10181018 // enough to be worth decoding? If so, wait until the next task loop
10191019 // to see if we've slowed down or disappeared.
1020+ // We're using the large of height or width of the window in physical
1021+ // pixels. This operation compares physical pixels (the window
1022+ // dimension) with logical pixels (the scrolling velocity). Using
1023+ // logical window pixels results in being too aggressive about loading
1024+ // images, and physical pixels will give us a better approximation of
1025+ // how much RAM is available.
10201026 // It's safe to use these calls as point-in-time - do not subscribe to
10211027 // updates of MediaQuery or Scrollable.
1022- final double maxPhysicalDimension = WidgetsBinding .instance.window.physicalSize.longestSide;
1023- if ((Scrollable .scrollingVelocityOfContext (context) ?? 0 ).abs () > maxPhysicalDimension ) {
1028+ final double maxPhysicalPixels = WidgetsBinding .instance.window.physicalSize.longestSide;
1029+ if ((Scrollable .scrollingVelocityOfContext (context) ?? 0 ).abs () > maxPhysicalPixels ) {
10241030 return DeferringImageProviderAction .defer;
10251031 }
10261032 // Ok, either not scrolling or scrolling slowly enough.
Original file line number Diff line number Diff line change @@ -676,6 +676,9 @@ abstract class ScrollPosition extends ViewportOffset with ScrollMetrics {
676676 ScrollActivity _activity;
677677
678678 /// The current [ScrollActivity.velocity] of the current activity, if any.
679+ ///
680+ /// This value is in logical pixels per second. It may be positive, negative,
681+ /// 0, or null.
679682 double get currentScrollVelocity => activity? .velocity;
680683
681684 /// Change the current [activity] , disposing of the old one and
Original file line number Diff line number Diff line change @@ -256,6 +256,9 @@ class Scrollable extends StatefulWidget {
256256 ///
257257 /// This does _not_ cause callers to subscribe to updates of this widget, and
258258 /// is only safe to use as a single point in time reference.
259+ ///
260+ /// This value is in logical pixels per second. It may be positive, negative,
261+ /// 0, or null.
259262 static double scrollingVelocityOfContext (BuildContext context) {
260263 final _ScrollableScope widget = context.getElementForInheritedWidgetOfExactType <_ScrollableScope >()? .widget as _ScrollableScope ;
261264 return widget? .scrollable? .position? .currentScrollVelocity;
You can’t perform that action at this time.
0 commit comments