Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
1 change: 1 addition & 0 deletions packages/flutter_image/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## NEXT

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

## 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(cyanglaz): migrate to use the new APIs
// https://github.com/flutter/flutter/issues/105336
Copy link
Collaborator

Choose a reason for hiding this comment

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

This issue is about APIs deprecated a year ago, so shouldn't still be applicable to new code. If there's a new migration needed, there should be a new issue describing it clearly (the old API, the new API, and the version it's in).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

// 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
8 changes: 4 additions & 4 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
// ignore: deprecated_member_use
Copy link
Collaborator

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
// ignore: deprecated_member_use
Copy link
Collaborator

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