Skip to content

Commit 4b56df1

Browse files
authored
fix(web): fix some casting issue on Web JS Interop (#12852)
* fix(web): fix some casting issue on Web JS Interop * format
1 parent 77ceb1f commit 4b56df1

File tree

13 files changed

+48
-23
lines changed

13 files changed

+48
-23
lines changed

Diff for: analysis_options.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ include: all_lint_rules.yaml
66
analyzer:
77
# TODO(rrousselGit): disable implicit-cast/implicit-dynamic
88
errors:
9-
import_of_legacy_library_into_null_safe: ignore
109
# Otherwise cause the import of all_lint_rules to warn because of some rules conflicts.
1110
# We explicitly enabled even conflicting rules and are fixing the conflict
1211
# in this file
@@ -43,6 +42,8 @@ linter:
4342
prefer_mixin: false
4443
public_member_api_docs: false
4544

45+
invalid_runtime_check_with_js_interop_types: true
46+
4647
#############
4748

4849
# Far too verbose, and not that big of a deal when using parameter_assignments

Diff for: packages/cloud_firestore/cloud_firestore_web/lib/src/interop/firestore.dart

+4
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,14 @@ class LoadBundleTaskProgress
257257
LoadBundleTaskProgress._fromJsObject(
258258
firestore_interop.LoadBundleTaskProgressJsImpl jsObject,
259259
) : taskState = convertToTaskState(jsObject.taskState.toDart.toLowerCase()),
260+
// Cannot be done with Dart 3.2 constraints
261+
// ignore: invalid_runtime_check_with_js_interop_types
260262
bytesLoaded = jsObject.bytesLoaded is JSNumber
261263
? (jsObject.bytesLoaded as JSNumber).toDartInt
262264
: int.parse((jsObject.bytesLoaded as JSString).toDart),
263265
documentsLoaded = jsObject.documentsLoaded.toDartInt,
266+
// Cannot be done with Dart 3.2 constraints
267+
// ignore: invalid_runtime_check_with_js_interop_types
264268
totalBytes = jsObject.totalBytes is JSNumber
265269
? (jsObject.totalBytes as JSNumber).toDartInt
266270
: int.parse((jsObject.totalBytes as JSString).toDart),

Diff for: packages/cloud_firestore/cloud_firestore_web/lib/src/interop/utils/utils.dart

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import '../firestore.dart';
1212
/// Returns Dart representation from JS Object.
1313
dynamic dartify(dynamic object) {
1414
// Convert JSObject to Dart equivalents directly
15+
// Cannot be done with Dart 3.2 constraints
16+
// ignore: invalid_runtime_check_with_js_interop_types
1517
if (object is! JSObject) {
1618
return object;
1719
}
@@ -85,11 +87,14 @@ JSAny? jsify(Object? dartObject) {
8587
return jsifyFieldValue(dartObject);
8688
}
8789

90+
// Cannot be done with Dart 3.2 constraints
91+
// ignore: invalid_runtime_check_with_js_interop_types
8892
if (dartObject is BytesJsImpl) {
8993
return dartObject as JSAny;
9094
}
9195

92-
// NOTE: if the firestore JS lib is not imported, we'll get a DDC warning here
96+
// Cannot be done with Dart 3.2 constraints
97+
// ignore: invalid_runtime_check_with_js_interop_types
9398
if (dartObject is GeoPointJsImpl) {
9499
return dartObject as JSAny;
95100
}

Diff for: packages/cloud_firestore/cloud_firestore_web/lib/src/utils/decode_utility.dart

+4
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,16 @@ class DecodeUtility {
3535
/// Decodes an incoming value to its proper type.
3636
static dynamic valueDecode(
3737
dynamic value, FirebaseFirestorePlatform firestore) {
38+
// Cannot be done with Dart 3.2 constraints
39+
// ignore: invalid_runtime_check_with_js_interop_types
3840
if (value is JSObject &&
3941
value.instanceof(GeoPointConstructor as JSFunction)) {
4042
return GeoPoint((value as GeoPointJsImpl).latitude.toDartDouble,
4143
(value as GeoPointJsImpl).longitude.toDartDouble);
4244
} else if (value is DateTime) {
4345
return Timestamp.fromDate(value);
46+
// Cannot be done with Dart 3.2 constraints
47+
// ignore: invalid_runtime_check_with_js_interop_types
4448
} else if (value is JSObject &&
4549
value.instanceof(BytesConstructor as JSFunction)) {
4650
return Blob((value as BytesJsImpl).toUint8Array().toDart);

Diff for: packages/cloud_functions/cloud_functions_web/lib/interop/functions.dart

+2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ class HttpsCallable extends JsObjectWrapper<JSFunction> {
8989
/// Returns Dart representation from JS Object.
9090
dynamic _dartify(dynamic object) {
9191
// Convert JSObject to Dart equivalents directly
92+
// Cannot be done with Dart 3.2 constraints
93+
// ignore: invalid_runtime_check_with_js_interop_types
9294
if (object is! JSObject) {
9395
return object;
9496
}

Diff for: packages/firebase_analytics/firebase_analytics_web/lib/interop/analytics.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Analytics extends JsObjectWrapper<analytics_interop.AnalyticsJsImpl> {
3434

3535
static Future<bool> isSupported() async {
3636
final result = await analytics_interop.isSupported().toDart;
37-
return result! as bool;
37+
return (result! as JSBoolean).toDart;
3838
}
3939

4040
/// Non-null App for this instance of analytics service.

Diff for: packages/firebase_auth/firebase_auth_web/lib/firebase_auth_web.dart

+2
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,8 @@ class FirebaseAuthWeb extends FirebaseAuthPlatform {
489489
.setItem(getOriginName(delegate.app.name), origin);
490490
}
491491
} catch (e) {
492+
// Cannot be done with 3.2 constraints
493+
// ignore: invalid_runtime_check_with_js_interop_types
492494
if (e is auth_interop.AuthError) {
493495
final String code = e.code.toDart;
494496
// this catches Firebase Error from web that occurs after hot reloading & hot restarting

Diff for: packages/firebase_auth/firebase_auth_web/lib/src/firebase_auth_web_recaptcha_verifier_factory.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class RecaptchaVerifierFactoryWeb extends RecaptchaVerifierFactoryPlatform {
154154
@override
155155
Future<int> render() async {
156156
try {
157-
return (await _delegate.render()).toInt();
157+
return await _delegate.render();
158158
} catch (e) {
159159
throw getFirebaseAuthException(e);
160160
}

Diff for: packages/firebase_auth/firebase_auth_web/lib/src/interop/auth.dart

+7-7
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class User extends UserInfo<auth_interop.UserJsImpl> {
127127
Future<String> getIdToken([bool forceRefresh = false]) => jsObject
128128
.getIdToken(forceRefresh.toJS)
129129
.toDart
130-
.then((value) => value! as String);
130+
.then((value) => (value! as JSString).toDart);
131131

132132
/// Links the user account with the given credentials, and returns any
133133
/// available additional user information, such as user name.
@@ -526,7 +526,7 @@ class Auth extends JsObjectWrapper<auth_interop.AuthJsImpl> {
526526
Future<List<String>> fetchSignInMethodsForEmail(String email) => auth_interop
527527
.fetchSignInMethodsForEmail(jsObject, email.toJS)
528528
.toDart
529-
.then((value) => List<String>.from(value! as List<dynamic>));
529+
.then((value) => List<String>.from((value! as JSArray).toDart));
530530

531531
/// Checks if an incoming link is a sign-in with email link.
532532
bool isSignInWithEmailLink(String emailLink) =>
@@ -753,7 +753,7 @@ class Auth extends JsObjectWrapper<auth_interop.AuthJsImpl> {
753753
Future<String> verifyPasswordResetCode(String code) => auth_interop
754754
.verifyPasswordResetCode(jsObject, code.toJS)
755755
.toDart
756-
.then((value) => value! as String);
756+
.then((value) => (value! as JSString).toDart);
757757
}
758758

759759
/// Represents an auth provider.
@@ -1054,7 +1054,7 @@ class PhoneAuthProvider
10541054
jsObject
10551055
.verifyPhoneNumber(phoneOptions, applicationVerifier.jsObject)
10561056
.toDart
1057-
.then((value) => value! as String);
1057+
.then((value) => (value! as JSString).toDart);
10581058

10591059
/// Creates a phone auth credential given the verification ID
10601060
/// from [verifyPhoneNumber] and the [verificationCode] that was sent to the
@@ -1081,7 +1081,7 @@ abstract class ApplicationVerifier<
10811081
/// Returns a Future containing string for a token that can be used to
10821082
/// assert the validity of a request.
10831083
Future<String> verify() =>
1084-
jsObject.verify().toDart.then((value) => value! as String);
1084+
jsObject.verify().toDart.then((value) => (value! as JSString).toDart);
10851085
}
10861086

10871087
/// reCAPTCHA verifier.
@@ -1137,8 +1137,8 @@ class RecaptchaVerifier
11371137

11381138
/// Renders the reCAPTCHA widget on the page.
11391139
/// Returns a Future that resolves with the reCAPTCHA widget ID.
1140-
Future<num> render() =>
1141-
jsObject.render().toDart.then((value) => value! as num);
1140+
Future<int> render() =>
1141+
jsObject.render().toDart.then((value) => (value! as JSNumber).toDartInt);
11421142
}
11431143

11441144
/// A result from a phone number sign-in, link, or reauthenticate call.

Diff for: packages/firebase_core/firebase_core_web/lib/src/firebase_core_web.dart

+3
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ class FirebaseCoreWeb extends FirebasePlatform {
8787
JSObject? ignored =
8888
globalContext.getProperty('flutterfire_ignore_scripts'.toJS);
8989

90+
// Cannot be done with Dart 3.2 constraints
91+
// ignore: invalid_runtime_check_with_js_interop_types
9092
if (ignored is Iterable) {
93+
// ignore: invalid_runtime_check_with_js_interop_types
9194
return (ignored! as Iterable)
9295
.map((e) => e.toString())
9396
.toList(growable: false);

Diff for: packages/firebase_messaging/firebase_messaging_web/lib/firebase_messaging_web.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class FirebaseMessagingWeb extends FirebaseMessagingPlatform {
145145
}) {
146146
return convertWebExceptions(() async {
147147
String status =
148-
(await web.Notification.requestPermission().toDart) as String;
148+
(await web.Notification.requestPermission().toDart).toDart;
149149
return utils.getNotificationSettings(status);
150150
});
151151
}

Diff for: packages/firebase_messaging/firebase_messaging_web/lib/src/interop/messaging.dart

+13-9
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ class Messaging extends JsObjectWrapper<messaging_interop.MessagingJsImpl> {
3131
return _expando[jsObject] ??= Messaging._fromJsObject(jsObject);
3232
}
3333

34-
static Future<bool> isSupported() =>
35-
messaging_interop.isSupported().toDart.then((value) => value! as bool);
34+
static Future<bool> isSupported() => messaging_interop
35+
.isSupported()
36+
.toDart
37+
.then((value) => (value! as JSBoolean).toDart);
3638

3739
Messaging._fromJsObject(messaging_interop.MessagingJsImpl jsObject)
3840
: super.fromJsObject(jsObject);
@@ -45,13 +47,15 @@ class Messaging extends JsObjectWrapper<messaging_interop.MessagingJsImpl> {
4547
/// that can be used to send push messages to this user.
4648
Future<String> getToken({String? vapidKey}) async {
4749
try {
48-
final token = (await messaging_interop
49-
.getToken(
50-
jsObject,
51-
vapidKey == null
52-
? null
53-
: messaging_interop.GetTokenOptions(vapidKey: vapidKey.toJS))
54-
.toDart)! as String;
50+
final token = ((await messaging_interop
51+
.getToken(
52+
jsObject,
53+
vapidKey == null
54+
? null
55+
: messaging_interop.GetTokenOptions(
56+
vapidKey: vapidKey.toJS))
57+
.toDart)! as JSString)
58+
.toDart;
5559
return token;
5660
} catch (err) {
5761
// A race condition can happen in which the service worker get registered

Diff for: packages/firebase_remote_config/firebase_remote_config_web/lib/src/interop/firebase_remote_config.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class RemoteConfig
8686
Future<bool> activate() async => remote_config_interop
8787
.activate(jsObject)
8888
.toDart
89-
.then((value) => value! as bool);
89+
.then((value) => (value! as JSBoolean).toDart);
9090

9191
/// Ensures the last activated config are available to the getters.
9292
Future<void> ensureInitialized() async =>
@@ -101,7 +101,7 @@ class RemoteConfig
101101
/// If the fetched configs were already activated, the promise will resolve to false.
102102
Future<bool> fetchAndActivate() async =>
103103
remote_config_interop.fetchAndActivate(jsObject).toDart.then(
104-
(value) => value! as bool,
104+
(value) => (value! as JSBoolean).toDart,
105105
);
106106

107107
/// Returns all config values.

0 commit comments

Comments
 (0)