File tree 4 files changed +13
-30
lines changed
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> {
38
38
39
39
@override
40
40
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);
42
42
if (result is Future <R >) {
43
43
return result;
44
44
}
45
- return SynchronousFuture <R >(result);
45
+ return SynchronousFuture <R >(result as R );
46
46
}
47
47
48
48
@override
Original file line number Diff line number Diff line change @@ -247,24 +247,17 @@ abstract class CachingAssetBundle extends AssetBundle {
247
247
/// An [AssetBundle] that loads resources using platform messages.
248
248
class PlatformAssetBundle extends CachingAssetBundle {
249
249
@override
250
- Future <ByteData > load (String key) {
250
+ Future <ByteData > load (String key) async {
251
251
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 ) {
262
255
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
+ ]);
266
259
}
267
- return future ;
260
+ return asset ;
268
261
}
269
262
270
263
@override
Original file line number Diff line number Diff line change @@ -6,8 +6,8 @@ import 'dart:async';
6
6
import 'dart:convert' ;
7
7
import 'dart:io' ;
8
8
9
- import 'package:flutter/foundation.dart' ;
10
9
import 'package:flutter/services.dart' ;
10
+ import 'package:flutter/widgets.dart' ;
11
11
import 'package:path/path.dart' as path;
12
12
// ignore: deprecated_member_use
13
13
import 'package:test_api/test_api.dart' as test_package;
@@ -42,7 +42,7 @@ void mockFlutterAssets() {
42
42
/// platform messages.
43
43
SystemChannels .navigation.setMockMethodCallHandler ((MethodCall methodCall) async {});
44
44
45
- ServicesBinding .instance.defaultBinaryMessenger.setMockMessageHandler ('flutter/assets' , (ByteData ? message) {
45
+ ServicesBinding .instance.defaultBinaryMessenger.setMockMessageHandler ('flutter/assets' , (ByteData ? message) async {
46
46
assert (message != null );
47
47
String key = utf8.decode (message! .buffer.asUint8List ());
48
48
File asset = File (path.join (assetFolderPath, key));
@@ -62,7 +62,7 @@ void mockFlutterAssets() {
62
62
}
63
63
64
64
final Uint8List encoded = Uint8List .fromList (asset.readAsBytesSync ());
65
- return SynchronousFuture <ByteData >(encoded.buffer.asByteData ());
65
+ return Future <ByteData >. value (encoded.buffer.asByteData ());
66
66
});
67
67
}
68
68
Original file line number Diff line number Diff line change 10
10
import 'dart:async' ;
11
11
import 'dart:io' ;
12
12
13
- import 'package:flutter/services.dart' ;
14
13
import 'package:flutter/widgets.dart' ;
15
14
import 'package:flutter_test/flutter_test.dart' ;
16
15
@@ -91,13 +90,4 @@ void main() {
91
90
binding.idle ();
92
91
});
93
92
});
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
- });
103
93
}
You can’t perform that action at this time.
0 commit comments