Complete the Scene.toImage future with an error if rasterization fails (flutter/engine#24877)

Also fix the nullability annotations on _futurize

Fixes https://github.com/flutter/flutter/issues/76591
This commit is contained in:
Jason Simmons
2021-03-10 16:51:27 -08:00
committed by GitHub
parent 8c6f4a36de
commit 300a119335
2 changed files with 9 additions and 5 deletions

View File

@@ -31,13 +31,17 @@ class Scene extends NativeFieldWrapperClass2 {
if (width <= 0 || height <= 0) {
throw Exception('Invalid image dimensions.');
}
return _futurize((_Callback<Image> callback) => _toImage(width, height, (_Image image) {
callback(Image._(image));
return _futurize((_Callback<Image?> 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.
///

View File

@@ -5273,7 +5273,7 @@ typedef _Callback<T> = void Function(T result);
///
/// Return value should be null on success, and a string error message on
/// failure.
typedef _Callbacker<T> = String? Function(_Callback<T> callback);
typedef _Callbacker<T> = String? Function(_Callback<T?> callback);
/// Converts a method that receives a value-returning callback to a method that
/// returns a Future.
@@ -5298,7 +5298,7 @@ typedef _Callbacker<T> = String? Function(_Callback<T> callback);
/// ```
Future<T> _futurize<T>(_Callbacker<T> callbacker) {
final Completer<T> completer = Completer<T>.sync();
final String? error = callbacker((T t) {
final String? error = callbacker((T? t) {
if (t == null) {
completer.completeError(Exception('operation failed'));
} else {