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+
15import 'dart:async' ;
26import 'dart:typed_data' ;
37import 'dart:ui' as ui;
@@ -9,13 +13,11 @@ import 'package:flutter/foundation.dart'
913 show SynchronousFuture, describeIdentity;
1014
1115class _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+ }) {
1921 codec.then <void >(_onCodecReady, onError: (dynamic error, StackTrace stack) {
2022 reportError (
2123 context: ErrorDescription ('resolving a single-frame image stream' ),
@@ -27,6 +29,9 @@ class _FutureImageStreamCompleter extends ImageStreamCompleter {
2729 });
2830 }
2931
32+ final Future <double > futureScale;
33+ final InformationCollector ? informationCollector;
34+
3035 Future <void > _onCodecReady (ui.Codec codec) async {
3136 try {
3237 ui.FrameInfo nextFrame = await codec.getNextFrame ();
@@ -50,9 +55,7 @@ class _FutureMemoryImage extends ImageProvider<_FutureMemoryImage> {
5055 /// Constructor for FutureMemoryImage. [_futureBytes] is the bytes that will
5156 /// be loaded into an image and [_futureScale] is the scale that will be applied to
5257 /// 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);
5659
5760 final Future <Uint8List > _futureBytes;
5861 final Future <double > _futureScale;
@@ -73,7 +76,9 @@ class _FutureMemoryImage extends ImageProvider<_FutureMemoryImage> {
7376 }
7477
7578 Future <ui.Codec > _loadAsync (
76- _FutureMemoryImage key, DecoderCallback decode) async {
79+ _FutureMemoryImage key,
80+ DecoderCallback decode,
81+ ) async {
7782 assert (key == this );
7883 return _futureBytes.then ((Uint8List bytes) {
7984 return decode (bytes);
@@ -113,10 +118,19 @@ class IosPlatformImages {
113118 ///
114119 /// See [https://developer.apple.com/documentation/uikit/uiimage/1624146-imagenamed?language=objc]
115120 static ImageProvider load (String name) {
116- Future <Map > loadInfo = _channel.invokeMethod ('loadImage' , name);
121+ Future <Map ? > loadInfo = _channel.invokeMapMethod ('loadImage' , name);
117122 Completer <Uint8List > bytesCompleter = Completer <Uint8List >();
118123 Completer <double > scaleCompleter = Completer <double >();
119124 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+ }
120134 scaleCompleter.complete (map["scale" ]);
121135 bytesCompleter.complete (map["data" ]);
122136 });
@@ -129,7 +143,7 @@ class IosPlatformImages {
129143 /// Returns null if the resource can't be found.
130144 ///
131145 /// 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 ]);
134148 }
135149}
0 commit comments