Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 4a5b739

Browse files
Complete the Scene.toImage future with an error if rasterization fails (#24877)
Also fix the nullability annotations on _futurize Fixes flutter/flutter#76591
1 parent 4813ed0 commit 4a5b739

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

lib/ui/compositing.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,17 @@ class Scene extends NativeFieldWrapperClass2 {
3131
if (width <= 0 || height <= 0) {
3232
throw Exception('Invalid image dimensions.');
3333
}
34-
return _futurize((_Callback<Image> callback) => _toImage(width, height, (_Image image) {
35-
callback(Image._(image));
34+
return _futurize((_Callback<Image?> callback) => _toImage(width, height, (_Image? image) {
35+
if (image == null) {
36+
callback(null);
37+
} else {
38+
callback(Image._(image));
39+
}
3640
}),
3741
);
3842
}
3943

40-
String? _toImage(int width, int height, _Callback<_Image> callback) native 'Scene_toImage';
44+
String? _toImage(int width, int height, _Callback<_Image?> callback) native 'Scene_toImage';
4145

4246
/// Releases the resources used by this scene.
4347
///

lib/ui/painting.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5273,7 +5273,7 @@ typedef _Callback<T> = void Function(T result);
52735273
///
52745274
/// Return value should be null on success, and a string error message on
52755275
/// failure.
5276-
typedef _Callbacker<T> = String? Function(_Callback<T> callback);
5276+
typedef _Callbacker<T> = String? Function(_Callback<T?> callback);
52775277

52785278
/// Converts a method that receives a value-returning callback to a method that
52795279
/// returns a Future.
@@ -5298,7 +5298,7 @@ typedef _Callbacker<T> = String? Function(_Callback<T> callback);
52985298
/// ```
52995299
Future<T> _futurize<T>(_Callbacker<T> callbacker) {
53005300
final Completer<T> completer = Completer<T>.sync();
5301-
final String? error = callbacker((T t) {
5301+
final String? error = callbacker((T? t) {
53025302
if (t == null) {
53035303
completer.completeError(Exception('operation failed'));
53045304
} else {

0 commit comments

Comments
 (0)