diff --git a/lib/web_ui/lib/src/engine/app_bootstrap.dart b/lib/web_ui/lib/src/engine/app_bootstrap.dart index 6d76f0c005c84..f930b87b6f4ce 100644 --- a/lib/web_ui/lib/src/engine/app_bootstrap.dart +++ b/lib/web_ui/lib/src/engine/app_bootstrap.dart @@ -40,30 +40,17 @@ class AppBootstrap { // This is a convenience method that lets the programmer call "autoStart" // from JavaScript immediately after the main.dart.js has loaded. // Returns a promise that resolves to the Flutter app that was started. - autoStart: allowInterop(() { - return Promise(allowInterop(( - PromiseResolver resolve, - PromiseRejecter _, - ) async { - await autoStart(); - // Return the App that was just started - resolve(_prepareFlutterApp()); - })); - }), + autoStart: allowInterop(() => futureToPromise(() async { + await autoStart(); + // Return the App that was just started + return _prepareFlutterApp(); + }())), // Calls [_initEngine], and returns a JS Promise that resolves to an // app runner object. - initializeEngine: allowInterop(([JsFlutterConfiguration? configuration]) { - // `params` coming from Javascript may be used to configure the engine intialization. - // The internal `initEngine` function must accept those params. - return Promise(allowInterop(( - PromiseResolver resolve, - PromiseRejecter _, - ) async { - await _initializeEngine(configuration); - // Return an app runner object - resolve(_prepareAppRunner()); - })); - }), + initializeEngine: allowInterop(([JsFlutterConfiguration? configuration]) => futureToPromise(() async { + await _initializeEngine(configuration); + return _prepareAppRunner(); + }())) ); } @@ -77,7 +64,7 @@ class AppBootstrap { ) async { await _runApp(); // Return the App that was just started - resolve(_prepareFlutterApp()); + resolve.resolve(_prepareFlutterApp()); })); })); } diff --git a/lib/web_ui/lib/src/engine/canvaskit/canvaskit_api.dart b/lib/web_ui/lib/src/engine/canvaskit/canvaskit_api.dart index 9f413f73ca87c..61682411d2734 100644 --- a/lib/web_ui/lib/src/engine/canvaskit/canvaskit_api.dart +++ b/lib/web_ui/lib/src/engine/canvaskit/canvaskit_api.dart @@ -176,9 +176,9 @@ class ColorSpace {} @staticInterop class SkWebGLContextOptions { external factory SkWebGLContextOptions({ - required int antialias, + required double antialias, // WebGL version: 1 or 2. - required int majorVersion, + required double majorVersion, }); } @@ -1362,7 +1362,8 @@ final SkFloat32List _sharedSkColor3 = mallocFloat32List(4); @JS('window.flutterCanvasKit.Path') @staticInterop class SkPath { - external factory SkPath([SkPath? other]); + external factory SkPath(); + external factory SkPath.from(SkPath other); } extension SkPathExtension on SkPath { diff --git a/lib/web_ui/lib/src/engine/canvaskit/surface.dart b/lib/web_ui/lib/src/engine/canvaskit/surface.dart index d0fc7a3ee4bfe..ff9d829f7aea6 100644 --- a/lib/web_ui/lib/src/engine/canvaskit/surface.dart +++ b/lib/web_ui/lib/src/engine/canvaskit/surface.dart @@ -325,7 +325,7 @@ class Surface { // Default to no anti-aliasing. Paint commands can be explicitly // anti-aliased by setting their `Paint` object's `antialias` property. antialias: _kUsingMSAA ? 1 : 0, - majorVersion: webGLVersion, + majorVersion: webGLVersion.toDouble(), ), ).toInt(); diff --git a/lib/web_ui/lib/src/engine/js_interop/js_loader.dart b/lib/web_ui/lib/src/engine/js_interop/js_loader.dart index 50a9ce5b544b1..1584b46d30975 100644 --- a/lib/web_ui/lib/src/engine/js_interop/js_loader.dart +++ b/lib/web_ui/lib/src/engine/js_interop/js_loader.dart @@ -54,7 +54,7 @@ abstract class FlutterEngineInitializer{ /// [JsFlutterConfiguration] comes from `../configuration.dart`. It is the same /// object that can be used to configure flutter "inline", through the /// (to be deprecated) `window.flutterConfiguration` object. -typedef InitializeEngineFn = Promise Function([JsFlutterConfiguration?]); +typedef InitializeEngineFn = Promise Function([JsFlutterConfiguration?]); /// Typedef for the `autoStart` function that can be called straight from an engine initializer instance. /// (Similar to [RunAppFn], but taking no specific "runApp" parameters). diff --git a/lib/web_ui/lib/src/engine/js_interop/js_promise.dart b/lib/web_ui/lib/src/engine/js_interop/js_promise.dart index 45f3f3b3482da..9a7f9ca6951b4 100644 --- a/lib/web_ui/lib/src/engine/js_interop/js_promise.dart +++ b/lib/web_ui/lib/src/engine/js_interop/js_promise.dart @@ -6,18 +6,39 @@ library js_promise; import 'package:js/js.dart'; +import 'package:js/js_util.dart' as js_util; + +@JS() +@staticInterop +class PromiseResolver {} + +extension PromiseResolverExtension on PromiseResolver { + void resolve(T result) => js_util.callMethod(this, 'call', [this, if (result != null) result]); +} + +@JS() +@staticInterop +class PromiseRejecter {} + +extension PromiseRejecterExtension on PromiseRejecter { + void reject(Object? error) => js_util.callMethod(this, 'call', [this, if (error != null) error]); +} /// Type-safe JS Promises @JS('Promise') @staticInterop -abstract class Promise { +abstract class Promise { /// A constructor for a JS promise external factory Promise(PromiseExecutor executor); } /// The type of function that is used to create a Promise -typedef PromiseExecutor = void Function(PromiseResolver resolve, PromiseRejecter reject); -/// The type of function used to resolve a Promise -typedef PromiseResolver = void Function(T result); -/// The type of function used to reject a Promise (of any ) -typedef PromiseRejecter = void Function(Object? error); +typedef PromiseExecutor = void Function(PromiseResolver resolve, PromiseRejecter reject); + +Promise futureToPromise(Future future) { + return Promise(allowInterop((PromiseResolver resolver, PromiseRejecter rejecter) { + future.then( + (T value) => resolver.resolve(value), + onError: (Object? error) => rejecter.reject(error)); + })); +} diff --git a/lib/web_ui/lib/src/engine/navigation/history.dart b/lib/web_ui/lib/src/engine/navigation/history.dart index bbee4c807bb58..0cc335cfd0243 100644 --- a/lib/web_ui/lib/src/engine/navigation/history.dart +++ b/lib/web_ui/lib/src/engine/navigation/history.dart @@ -145,7 +145,7 @@ class MultiEntriesBrowserHistory extends BrowserHistory { if (_hasSerialCount(currentState)) { final Map stateMap = currentState! as Map; - return stateMap['serialCount'] as int; + return (stateMap['serialCount'] as double).toInt(); } return 0; }