Skip to content

Commit

Permalink
Remove deprecated ImageProvider methods (#4725)
Browse files Browse the repository at this point in the history
Have to keep `loadBuffer` since `loadImage` isn't available on 3.7. 
Fixes flutter/flutter#105336
  • Loading branch information
LongCatIsLooong committed Aug 22, 2023
1 parent c730a90 commit 354af05
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 21 deletions.
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
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
PaintingBinding.instance.instantiateImageCodec,
PaintingBinding.instance.instantiateImageCodecFromBuffer,
);
completer.addListener(ImageStreamListener(
expectAsync2((ImageInfo image, bool synchronousCall) {
Expand Down

0 comments on commit 354af05

Please sign in to comment.