1
+ // Copyright 2020 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
1
5
import 'dart:async' ;
2
6
import 'dart:typed_data' ;
3
7
import 'dart:ui' as ui;
@@ -9,13 +13,11 @@ import 'package:flutter/foundation.dart'
9
13
show SynchronousFuture, describeIdentity;
10
14
11
15
class _FutureImageStreamCompleter extends ImageStreamCompleter {
12
- final Future <double > futureScale;
13
- final InformationCollector informationCollector;
14
-
15
- _FutureImageStreamCompleter (
16
- {Future <ui.Codec > codec, this .futureScale, this .informationCollector})
17
- : assert (codec != null ),
18
- assert (futureScale != null ) {
16
+ _FutureImageStreamCompleter ({
17
+ required Future <ui.Codec > codec,
18
+ required this .futureScale,
19
+ this .informationCollector,
20
+ }) {
19
21
codec.then <void >(_onCodecReady, onError: (dynamic error, StackTrace stack) {
20
22
reportError (
21
23
context: ErrorDescription ('resolving a single-frame image stream' ),
@@ -27,6 +29,9 @@ class _FutureImageStreamCompleter extends ImageStreamCompleter {
27
29
});
28
30
}
29
31
32
+ final Future <double > futureScale;
33
+ final InformationCollector ? informationCollector;
34
+
30
35
Future <void > _onCodecReady (ui.Codec codec) async {
31
36
try {
32
37
ui.FrameInfo nextFrame = await codec.getNextFrame ();
@@ -50,9 +55,7 @@ class _FutureMemoryImage extends ImageProvider<_FutureMemoryImage> {
50
55
/// Constructor for FutureMemoryImage. [_futureBytes] is the bytes that will
51
56
/// be loaded into an image and [_futureScale] is the scale that will be applied to
52
57
/// that image to account for high-resolution images.
53
- const _FutureMemoryImage (this ._futureBytes, this ._futureScale)
54
- : assert (_futureBytes != null ),
55
- assert (_futureScale != null );
58
+ const _FutureMemoryImage (this ._futureBytes, this ._futureScale);
56
59
57
60
final Future <Uint8List > _futureBytes;
58
61
final Future <double > _futureScale;
@@ -73,7 +76,9 @@ class _FutureMemoryImage extends ImageProvider<_FutureMemoryImage> {
73
76
}
74
77
75
78
Future <ui.Codec > _loadAsync (
76
- _FutureMemoryImage key, DecoderCallback decode) async {
79
+ _FutureMemoryImage key,
80
+ DecoderCallback decode,
81
+ ) async {
77
82
assert (key == this );
78
83
return _futureBytes.then ((Uint8List bytes) {
79
84
return decode (bytes);
@@ -113,10 +118,19 @@ class IosPlatformImages {
113
118
///
114
119
/// See [https://developer.apple.com/documentation/uikit/uiimage/1624146-imagenamed?language=objc]
115
120
static ImageProvider load (String name) {
116
- Future <Map > loadInfo = _channel.invokeMethod ('loadImage' , name);
121
+ Future <Map ? > loadInfo = _channel.invokeMapMethod ('loadImage' , name);
117
122
Completer <Uint8List > bytesCompleter = Completer <Uint8List >();
118
123
Completer <double > scaleCompleter = Completer <double >();
119
124
loadInfo.then ((map) {
125
+ if (map == null ) {
126
+ scaleCompleter.completeError (
127
+ Exception ("Image couldn't be found: $name " ),
128
+ );
129
+ bytesCompleter.completeError (
130
+ Exception ("Image couldn't be found: $name " ),
131
+ );
132
+ return ;
133
+ }
120
134
scaleCompleter.complete (map["scale" ]);
121
135
bytesCompleter.complete (map["data" ]);
122
136
});
@@ -129,7 +143,7 @@ class IosPlatformImages {
129
143
/// Returns null if the resource can't be found.
130
144
///
131
145
/// See [https://developer.apple.com/documentation/foundation/nsbundle/1411540-urlforresource?language=objc]
132
- static Future <String > resolveURL (String name, [ String ext] ) {
133
- return _channel.invokeMethod <String >('resolveURL' , [name, ext ]);
146
+ static Future <String ? > resolveURL (String name, { String ? extension } ) {
147
+ return _channel.invokeMethod <String >('resolveURL' , [name, extension ]);
134
148
}
135
149
}
0 commit comments