[Breaking Change] ImageProvider load method use DecodeCallback

1,117 views
Skip to first unread message

Gary Qian

unread,
Oct 7, 2019, 8:15:54 PM10/7/19
to flutter-...@googlegroups.com
Hello Flutter developers,

If you do not have a custom implementation of ImageProvider, this change will not impact you.

Change

The following breaking change is proposed as part of https://github.com/flutter/flutter/pull/41415 to add the capability to decode images to a specified size in order to reduce ImageCache memory usage.

ImageProvider.load will take an additional positional parameter DecoderCallback decode

The new signature is:

  ImageStreamCompleter load(T key, DecoderCallback decode)

where DecodeCallback is:

  typedef DecoderCallback = Future<ui.Codec> Function(Uint8List bytes, {int cacheWidth, int cacheHeight});

Justification

This change is to provide a way to pass the cacheWidth and cacheHeight values into a load call without redundantly making all ImageProviders directly know about these parameters when it is irrelevant. ResizeImage supplies the values through a closure.

Overall, this change allows fine control of the decoded and cached sizes of images.

Migration

Full migration is recommended, however, If you wish your code to simply work as before with no support for ResizeImage, simply add DecoderCallback decode to the load signature.

Full migration will require you to call the decode callback in place of PaintingBinding.instance.instantiateImageCodec()

We welcome any feedback on this change or requests for assistance in migration through email or a direct comment on the PR linked above!

Thanks,
Gary
Reply all
Reply to author
Forward
0 new messages