Remove deprecated ImageProvider methods (#4725)

Have to keep `loadBuffer` since `loadImage` isn't available on 3.7. 
Fixes https://github.com/flutter/flutter/issues/105336
This commit is contained in:
LongCatIsLooong
2023-08-22 12:14:49 -07:00
committed by GitHub
parent c730a90f2f
commit 354af05222
4 changed files with 25 additions and 21 deletions

View File

@ -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

View File

@ -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
@ -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');
@ -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();
@ -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,

View File

@ -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"

View File

@ -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) {},
@ -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) {