File tree Expand file tree Collapse file tree 4 files changed +13
-30
lines changed Expand file tree Collapse file tree 4 files changed +13
-30
lines changed Original file line number Diff line number Diff line change @@ -38,11 +38,11 @@ class SynchronousFuture<T> implements Future<T> {
3838
3939 @override
4040 Future <R > then <R >(FutureOr <R > Function (T value) onValue, { Function ? onError }) {
41- final FutureOr < R > result = onValue (_value);
41+ final dynamic result = onValue (_value);
4242 if (result is Future <R >) {
4343 return result;
4444 }
45- return SynchronousFuture <R >(result);
45+ return SynchronousFuture <R >(result as R );
4646 }
4747
4848 @override
Original file line number Diff line number Diff line change @@ -247,24 +247,17 @@ abstract class CachingAssetBundle extends AssetBundle {
247247/// An [AssetBundle] that loads resources using platform messages.
248248class PlatformAssetBundle extends CachingAssetBundle {
249249 @override
250- Future <ByteData > load (String key) {
250+ Future <ByteData > load (String key) async {
251251 final Uint8List encoded = utf8.encoder.convert (Uri (path: Uri .encodeFull (key)).path);
252- final Future <ByteData >? future = ServicesBinding .instance.defaultBinaryMessenger.send ('flutter/assets' , encoded.buffer.asByteData ())? .then ((ByteData ? asset) {
253- if (asset == null ) {
254- throw FlutterError .fromParts (< DiagnosticsNode > [
255- _errorSummaryWithKey (key),
256- ErrorDescription ('The asset does not exist or has empty data.' ),
257- ]);
258- }
259- return asset;
260- });
261- if (future == null ) {
252+ final ByteData ? asset =
253+ await ServicesBinding .instance.defaultBinaryMessenger.send ('flutter/assets' , encoded.buffer.asByteData ());
254+ if (asset == null ) {
262255 throw FlutterError .fromParts (< DiagnosticsNode > [
263- _errorSummaryWithKey (key),
264- ErrorDescription ('The asset does not exist or has empty data.' ),
265- ]);
256+ _errorSummaryWithKey (key),
257+ ErrorDescription ('The asset does not exist or has empty data.' ),
258+ ]);
266259 }
267- return future ;
260+ return asset ;
268261 }
269262
270263 @override
Original file line number Diff line number Diff line change @@ -6,8 +6,8 @@ import 'dart:async';
66import 'dart:convert' ;
77import 'dart:io' ;
88
9- import 'package:flutter/foundation.dart' ;
109import 'package:flutter/services.dart' ;
10+ import 'package:flutter/widgets.dart' ;
1111import 'package:path/path.dart' as path;
1212// ignore: deprecated_member_use
1313import 'package:test_api/test_api.dart' as test_package;
@@ -42,7 +42,7 @@ void mockFlutterAssets() {
4242 /// platform messages.
4343 SystemChannels .navigation.setMockMethodCallHandler ((MethodCall methodCall) async {});
4444
45- ServicesBinding .instance.defaultBinaryMessenger.setMockMessageHandler ('flutter/assets' , (ByteData ? message) {
45+ ServicesBinding .instance.defaultBinaryMessenger.setMockMessageHandler ('flutter/assets' , (ByteData ? message) async {
4646 assert (message != null );
4747 String key = utf8.decode (message! .buffer.asUint8List ());
4848 File asset = File (path.join (assetFolderPath, key));
@@ -62,7 +62,7 @@ void mockFlutterAssets() {
6262 }
6363
6464 final Uint8List encoded = Uint8List .fromList (asset.readAsBytesSync ());
65- return SynchronousFuture <ByteData >(encoded.buffer.asByteData ());
65+ return Future <ByteData >. value (encoded.buffer.asByteData ());
6666 });
6767}
6868
Original file line number Diff line number Diff line change 1010import 'dart:async' ;
1111import 'dart:io' ;
1212
13- import 'package:flutter/services.dart' ;
1413import 'package:flutter/widgets.dart' ;
1514import 'package:flutter_test/flutter_test.dart' ;
1615
@@ -91,13 +90,4 @@ void main() {
9190 binding.idle ();
9291 });
9392 });
94-
95- testWidgets ('Assets in the tester can be loaded without turning event loop' , (WidgetTester tester) async {
96- bool responded = false ;
97- // The particular asset does not matter, as long as it exists.
98- rootBundle.load ('AssetManifest.json' ).then ((ByteData data) {
99- responded = true ;
100- });
101- expect (responded, true );
102- });
10393}
You can’t perform that action at this time.
0 commit comments