Skip to content

Remove deprecated ImageProvider methods #4725

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/flutter_image/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## NEXT
## 4.1.7

* Updates minimum supported SDK version to Flutter 3.7/Dart 2.19.
* Migrates deprecated `ImageProvider.load` to `ImageProvider.loadBuffer`.

## 4.1.6

Expand Down
25 changes: 14 additions & 11 deletions packages/flutter_image/lib/network.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import 'dart:ui' as ui;
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';

// Method signature for _loadWithRetry decode callbacks.
typedef _SimpleDecoderCallback = Future<ui.Codec> Function(
ui.ImmutableBuffer buffer);

/// Fetches the image from the given URL, associating it with the given scale.
///
/// If [fetchStrategy] is specified, uses it instead of the
Expand Down Expand Up @@ -95,10 +99,13 @@ class NetworkImageWithRetry extends ImageProvider<NetworkImageWithRetry> {
}

@override
// TODO(cyanglaz): migrate to use the new APIs
// https://github.com/flutter/flutter/issues/105336
// ignore: deprecated_member_use
ImageStreamCompleter load(NetworkImageWithRetry key, DecoderCallback decode) {
ImageStreamCompleter loadBuffer(
NetworkImageWithRetry key,
// TODO(LongCatIsLooong): migrate to use new `loadImage` API.
// https://github.com/flutter/flutter/issues/132856
// ignore: deprecated_member_use
DecoderBufferCallback decode,
) {
return OneFrameImageStreamCompleter(_loadWithRetry(key, decode),
informationCollector: () sync* {
yield ErrorDescription('Image provider: $this');
Expand Down Expand Up @@ -126,12 +133,7 @@ class NetworkImageWithRetry extends ImageProvider<NetworkImageWithRetry> {
}

Future<ImageInfo> _loadWithRetry(
// TODO(cyanglaz): migrate to use the new APIs
// https://github.com/flutter/flutter/issues/105336
// ignore: deprecated_member_use
NetworkImageWithRetry key,
// ignore: deprecated_member_use
DecoderCallback decode) async {
NetworkImageWithRetry key, _SimpleDecoderCallback decode) async {
assert(key == this);

final Stopwatch stopwatch = Stopwatch()..start();
Expand Down Expand Up @@ -181,7 +183,8 @@ class NetworkImageWithRetry extends ImageProvider<NetworkImageWithRetry> {
);
}

final ui.Codec codec = await decode(bytes);
final ui.Codec codec =
await decode(await ui.ImmutableBuffer.fromUint8List(bytes));
final ui.Image image = (await codec.getNextFrame()).image;
return ImageInfo(
image: image,
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter_image/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: >
Image utilities for Flutter: improved network providers, effects, etc.
repository: https://github.com/flutter/packages/tree/main/packages/flutter_image
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+flutter_image%22
version: 4.1.6
version: 4.1.7

environment:
sdk: ">=2.19.0 <4.0.0"
Expand Down
16 changes: 8 additions & 8 deletions packages/flutter_image/test/network_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,12 @@ void assertThatImageLoadingFails(
NetworkImageWithRetry subject,
List<FlutterErrorDetails> errorLog,
) {
final ImageStreamCompleter completer = subject.load(
final ImageStreamCompleter completer = subject.loadBuffer(
subject,
// TODO(cyanglaz): migrate to use the new APIs
// https://github.com/flutter/flutter/issues/105336
// TODO(LongCatIsLooong): migrate to use new `instantiateImageCodecWithSize` API.
// https://github.com/flutter/flutter/issues/132856
// ignore: deprecated_member_use
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This replacement is also deprecated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the up-to-date APIs are only available in >v3.7.0 unfortunately. Included in the new issue.

PaintingBinding.instance.instantiateImageCodec,
PaintingBinding.instance.instantiateImageCodecFromBuffer,
);
completer.addListener(ImageStreamListener(
(ImageInfo image, bool synchronousCall) {},
Expand All @@ -160,12 +160,12 @@ void assertThatImageLoadingFails(
void assertThatImageLoadingSucceeds(
NetworkImageWithRetry subject,
) {
final ImageStreamCompleter completer = subject.load(
final ImageStreamCompleter completer = subject.loadBuffer(
subject,
// TODO(cyanglaz): migrate to use the new APIs
// https://github.com/flutter/flutter/issues/105336
// TODO(LongCatIsLooong): migrate to use new `instantiateImageCodecWithSize` API.
// https://github.com/flutter/flutter/issues/132856
// ignore: deprecated_member_use
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question here.

PaintingBinding.instance.instantiateImageCodec,
PaintingBinding.instance.instantiateImageCodecFromBuffer,
);
completer.addListener(ImageStreamListener(
expectAsync2((ImageInfo image, bool synchronousCall) {
Expand Down