@@ -11,32 +11,30 @@ import 'dart:async';
1111import 'dart:js_interop' ;
1212import 'dart:js_interop_unsafe' ;
1313import 'package:web/web.dart' as web;
14- import 'package:flutter/foundation.dart' ;
1514
1615import 'func.dart' ;
1716
17+ // ignore: do_not_use_environment
18+ const bool _kDebugMode = ! bool .fromEnvironment ('dart.vm.product' );
19+
1820/// Handles the [Future] object with the provided [mapper] function.
1921JSPromise handleFutureWithMapper <T , S >(
20- Future <JSAny ? > future,
22+ Future <T > future,
2123 Func1 <T , S > mapper,
2224) {
23- // Taken from js_interop:286
2425 return JSPromise ((JSFunction resolve, JSFunction reject) {
25- future.then ((JSAny ? value) {
26- resolve.callAsFunction (resolve, value);
27- return value;
26+ future.then <void >((T value) {
27+ final Object ? target = mapper (value);
28+ final JSAny ? jsVal = target? .jsify ();
29+ resolve.callAsFunction (resolve, jsVal);
2830 }, onError: (Object error, StackTrace stackTrace) {
2931 final errorConstructor =
3032 globalContext.getProperty ('Error' .toJS)! as JSFunction ;
31- final wrapper = errorConstructor.callAsConstructor <JSObject >(
32- 'Dart exception thrown from converted Future. Use the properties '
33- "'error' to fetch the boxed error and 'stack' to recover "
34- 'the stack trace.'
35- .toJS);
33+ final wrapper = errorConstructor
34+ .callAsConstructor <JSObject >('Dart exception: $error ' .toJS);
3635 wrapper['error' ] = error.toJSBox;
3736 wrapper['stack' ] = stackTrace.toString ().toJS;
3837 reject.callAsFunction (reject, wrapper);
39- return wrapper;
4038 });
4139 }.toJS);
4240}
@@ -45,7 +43,7 @@ JSPromise handleFutureWithMapper<T, S>(
4543// and clean up on hot restart if it exists.
4644// See: https://github.com/firebase/flutterfire/issues/7064
4745void unsubscribeWindowsListener (String key) {
48- if (kDebugMode ) {
46+ if (_kDebugMode ) {
4947 final unsubscribe = web.window.getProperty (key.toJS);
5048 if (unsubscribe != null ) {
5149 (unsubscribe as JSFunction ).callAsFunction ();
@@ -54,13 +52,13 @@ void unsubscribeWindowsListener(String key) {
5452}
5553
5654void setWindowsListener (String key, JSFunction unsubscribe) {
57- if (kDebugMode ) {
55+ if (_kDebugMode ) {
5856 web.window.setProperty (key.toJS, unsubscribe);
5957 }
6058}
6159
6260void removeWindowsListener (String key) {
63- if (kDebugMode ) {
61+ if (_kDebugMode ) {
6462 if (web.window.hasProperty (key.toJS) == true .toJS) {
6563 web.window.delete (key.toJS);
6664 }
0 commit comments