Skip to content

Commit

Permalink
Fix deprecated load in mock image providers
Browse files Browse the repository at this point in the history
  • Loading branch information
renefloor committed Sep 25, 2023
1 parent 36ec247 commit 54ecab2
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:

# Run Flutter Format to ensure formatting is valid
- name: Run Flutter Format
run: flutter format --set-exit-if-changed .
run: flutter dart --set-exit-if-changed .
working-directory: ${{env.source-directory}}

analyze:
Expand Down
12 changes: 7 additions & 5 deletions example/lib/helpers/mock_image_provider.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:async' show Future, StreamController;
import 'dart:typed_data';
import 'dart:async';
import 'dart:ui' as ui show Codec;
import 'package:flutter/services.dart';
import 'package:http/http.dart' as http;

import 'package:flutter/foundation.dart';
Expand Down Expand Up @@ -33,7 +33,8 @@ class MockImageProvider extends ImageProvider<MockImageProvider> {
}

@override
ImageStreamCompleter load(MockImageProvider key, DecoderCallback decode) {
ImageStreamCompleter loadImage(
MockImageProvider key, ImageDecoderCallback decode) {
final chunkEvents = StreamController<ImageChunkEvent>();
return MultiFrameImageStreamCompleter(
codec: _loadAsync(key, chunkEvents, decode).first,
Expand All @@ -45,7 +46,7 @@ class MockImageProvider extends ImageProvider<MockImageProvider> {
Stream<ui.Codec> _loadAsync(
MockImageProvider key,
StreamController<ImageChunkEvent> chunkEvents,
DecoderCallback decode,
ImageDecoderCallback decode,
) async* {
try {
if (showLoading) {
Expand All @@ -62,7 +63,8 @@ class MockImageProvider extends ImageProvider<MockImageProvider> {
var url = 'https://blurha.sh/assets/images/img1.jpg';
Uint8List imageBytes;
imageBytes = (await http.get(Uri.parse(url))).bodyBytes;
var decodedImage = await decode(imageBytes);
final buffer = await ImmutableBuffer.fromUint8List(imageBytes);
var decodedImage = await decode(buffer);
yield decodedImage;
} finally {
await chunkEvents.close();
Expand Down
115 changes: 73 additions & 42 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,58 @@ packages:
dependency: transitive
description:
name: async
url: "https://pub.dartlang.org"
sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c"
url: "https://pub.dev"
source: hosted
version: "2.8.2"
version: "2.11.0"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66"
url: "https://pub.dev"
source: hosted
version: "2.1.0"
version: "2.1.1"
characters:
dependency: transitive
description:
name: characters
url: "https://pub.dartlang.org"
sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605"
url: "https://pub.dev"
source: hosted
version: "1.2.0"
version: "1.3.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
sha256: fb98c0f6d12c920a02ee2d998da788bca066ca5f148492b7085ee23372b12306
url: "https://pub.dev"
source: hosted
version: "1.3.1"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.dartlang.org"
sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf
url: "https://pub.dev"
source: hosted
version: "1.1.0"
version: "1.1.1"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.dartlang.org"
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
url: "https://pub.dev"
source: hosted
version: "1.15.0"
version: "1.18.0"
fake_async:
dependency: transitive
description:
name: fake_async
url: "https://pub.dartlang.org"
sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78"
url: "https://pub.dev"
source: hosted
version: "1.2.0"
version: "1.3.1"
flutter:
dependency: "direct main"
description: flutter
Expand All @@ -59,7 +66,8 @@ packages:
dependency: "direct dev"
description:
name: flutter_lints
url: "https://pub.dartlang.org"
sha256: b543301ad291598523947dc534aaddc5aaad597b709d2426d3a0e0d44c5cb493
url: "https://pub.dev"
source: hosted
version: "1.0.4"
flutter_test:
Expand All @@ -71,58 +79,65 @@ packages:
dependency: "direct main"
description:
name: http
url: "https://pub.dartlang.org"
sha256: "2ed163531e071c2c6b7c659635112f24cb64ecbebf6af46b550d536c0b1aa112"
url: "https://pub.dev"
source: hosted
version: "0.13.4"
http_parser:
dependency: transitive
description:
name: http_parser
url: "https://pub.dartlang.org"
sha256: e362d639ba3bc07d5a71faebb98cde68c05bfbcfbbb444b60b6f60bb67719185
url: "https://pub.dev"
source: hosted
version: "4.0.0"
lints:
dependency: transitive
description:
name: lints
url: "https://pub.dartlang.org"
sha256: a2c3d198cb5ea2e179926622d433331d8b58374ab8f29cdda6e863bd62fd369c
url: "https://pub.dev"
source: hosted
version: "1.0.1"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.dartlang.org"
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
url: "https://pub.dev"
source: hosted
version: "0.12.11"
version: "0.12.16"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.dartlang.org"
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
url: "https://pub.dev"
source: hosted
version: "0.1.3"
version: "0.5.0"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
url: "https://pub.dev"
source: hosted
version: "1.7.0"
version: "1.10.0"
octo_image:
dependency: "direct main"
description:
path: ".."
relative: true
source: path
version: "1.0.2"
version: "2.0.0"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
url: "https://pub.dev"
source: hosted
version: "1.8.0"
version: "1.8.3"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -132,57 +147,73 @@ packages:
dependency: transitive
description:
name: source_span
url: "https://pub.dartlang.org"
sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
url: "https://pub.dev"
source: hosted
version: "1.8.1"
version: "1.10.0"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.dartlang.org"
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
url: "https://pub.dev"
source: hosted
version: "1.10.0"
version: "1.11.1"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.dartlang.org"
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
url: "https://pub.dev"
source: hosted
version: "2.1.0"
version: "2.1.2"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.dartlang.org"
sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
url: "https://pub.dev"
source: hosted
version: "1.1.0"
version: "1.2.0"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84
url: "https://pub.dev"
source: hosted
version: "1.2.0"
version: "1.2.1"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
url: "https://pub.dev"
source: hosted
version: "0.4.8"
version: "0.6.1"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
sha256: "53bdf7e979cfbf3e28987552fd72f637e63f3c8724c9e56d9246942dc2fa36ee"
url: "https://pub.dev"
source: hosted
version: "1.3.0"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803"
url: "https://pub.dev"
source: hosted
version: "2.1.1"
version: "2.1.4"
web:
dependency: transitive
description:
name: web
sha256: "14f1f70c51119012600c5f1f60ca68efda5a9b6077748163c6af2893ec5df8fc"
url: "https://pub.dev"
source: hosted
version: "0.2.1-beta"
sdks:
dart: ">=2.14.0 <3.0.0"
dart: ">=3.2.0-157.0.dev <4.0.0"
15 changes: 9 additions & 6 deletions lib/src/octo_set.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,23 @@ class OctoSet {
required Widget text,
}) {
return OctoSet(

Check warning on line 41 in lib/src/octo_set.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/octo_set.dart#L41

Added line #L41 was not covered by tests
placeholderBuilder:
OctoPlaceholder.circleAvatar(backgroundColor: backgroundColor, text: text),
placeholderBuilder: OctoPlaceholder.circleAvatar(
backgroundColor: backgroundColor, text: text),
imageBuilder: OctoImageTransformer.circleAvatar(),
errorBuilder: OctoError.circleAvatar(backgroundColor: backgroundColor, text: text),
errorBuilder:
OctoError.circleAvatar(backgroundColor: backgroundColor, text: text),
);
}

/// Simple set to show [OctoPlaceholder.circularProgressIndicator] as
/// placeholder and [OctoError.icon] as error.
factory OctoSet.circularIndicatorAndIcon({bool showProgress = false}) {
return OctoSet(

Check warning on line 53 in lib/src/octo_set.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/octo_set.dart#L53

Added line #L53 was not covered by tests
placeholderBuilder: showProgress ? null : OctoPlaceholder.circularProgressIndicator(),
progressIndicatorBuilder:
showProgress ? OctoProgressIndicator.circularProgressIndicator() : null,
placeholderBuilder:
showProgress ? null : OctoPlaceholder.circularProgressIndicator(),
progressIndicatorBuilder: showProgress
? OctoProgressIndicator.circularProgressIndicator()
: null,
errorBuilder: OctoError.icon(),
);
}
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ homepage: https://github.com/Baseflow/octo_image

environment:
sdk: '>=2.12.0 <3.0.0'
flutter: '>=3.7.0'

dependencies:
flutter:
Expand Down
9 changes: 6 additions & 3 deletions test/helpers/mock_image_provider.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async' show Future, StreamController;
import 'dart:ui' as ui show Codec;
import 'dart:ui';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -33,7 +34,8 @@ class MockImageProvider extends ImageProvider<MockImageProvider> {
}

@override
ImageStreamCompleter load(MockImageProvider key, DecoderCallback decode) {
ImageStreamCompleter loadImage(
MockImageProvider key, ImageDecoderCallback decode) {
final chunkEvents = StreamController<ImageChunkEvent>();
return MultiFrameImageStreamCompleter(
codec: _loadAsync(key, chunkEvents, decode).first,
Expand All @@ -45,7 +47,7 @@ class MockImageProvider extends ImageProvider<MockImageProvider> {
Stream<ui.Codec> _loadAsync(
MockImageProvider key,
StreamController<ImageChunkEvent> chunkEvents,
DecoderCallback decode,
ImageDecoderCallback decode,
) async* {
try {
if (showLoading) {
Expand All @@ -58,7 +60,8 @@ class MockImageProvider extends ImageProvider<MockImageProvider> {
if (fail) {
throw Exception('Image loading failed');
}
var decodedImage = await decode(kTransparentImage);
final buffer = await ImmutableBuffer.fromUint8List(kTransparentImage);
var decodedImage = await decode(buffer);
yield decodedImage;
} finally {
await chunkEvents.close();
Expand Down

0 comments on commit 54ecab2

Please sign in to comment.