diff --git a/lib/ui/compositing.dart b/lib/ui/compositing.dart index 59a6e2fee8ba6..f2bd5473380f5 100644 --- a/lib/ui/compositing.dart +++ b/lib/ui/compositing.dart @@ -31,13 +31,17 @@ class Scene extends NativeFieldWrapperClass2 { if (width <= 0 || height <= 0) { throw Exception('Invalid image dimensions.'); } - return _futurize((_Callback callback) => _toImage(width, height, (_Image image) { - callback(Image._(image)); + return _futurize((_Callback callback) => _toImage(width, height, (_Image? image) { + if (image == null) { + callback(null); + } else { + callback(Image._(image)); + } }), ); } - String? _toImage(int width, int height, _Callback<_Image> callback) native 'Scene_toImage'; + String? _toImage(int width, int height, _Callback<_Image?> callback) native 'Scene_toImage'; /// Releases the resources used by this scene. /// diff --git a/lib/ui/painting.dart b/lib/ui/painting.dart index 95b742f180e43..d224d52d80f76 100644 --- a/lib/ui/painting.dart +++ b/lib/ui/painting.dart @@ -5239,7 +5239,7 @@ typedef _Callback = void Function(T result); /// /// Return value should be null on success, and a string error message on /// failure. -typedef _Callbacker = String? Function(_Callback callback); +typedef _Callbacker = String? Function(_Callback callback); /// Converts a method that receives a value-returning callback to a method that /// returns a Future. @@ -5264,7 +5264,7 @@ typedef _Callbacker = String? Function(_Callback callback); /// ``` Future _futurize(_Callbacker callbacker) { final Completer completer = Completer.sync(); - final String? error = callbacker((T t) { + final String? error = callbacker((T? t) { if (t == null) { completer.completeError(Exception('operation failed')); } else {