Skip to content

Commit f6e0824

Browse files
committed
fix(web): fix some casting issue on Web JS Interop
1 parent 35b78f0 commit f6e0824

File tree

31 files changed

+64
-78
lines changed

31 files changed

+64
-78
lines changed

analysis_options.yaml

Lines changed: 2 additions & 1 deletion
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

packages/_flutterfire_internals/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ repository: https://github.com/firebase/flutterfire/tree/master/packages/_flutte
55
version: 1.3.35
66

77
environment:
8-
sdk: '>=3.2.0 <4.0.0'
8+
sdk: ^3.4.0
99
flutter: '>=3.3.0'
1010

1111
dependencies:

packages/cloud_firestore/cloud_firestore_web/lib/src/interop/firestore.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,11 @@ class LoadBundleTaskProgress
257257
LoadBundleTaskProgress._fromJsObject(
258258
firestore_interop.LoadBundleTaskProgressJsImpl jsObject,
259259
) : taskState = convertToTaskState(jsObject.taskState.toDart.toLowerCase()),
260-
bytesLoaded = jsObject.bytesLoaded is JSNumber
260+
bytesLoaded = jsObject.bytesLoaded.isA<JSNumber>()
261261
? (jsObject.bytesLoaded as JSNumber).toDartInt
262262
: int.parse((jsObject.bytesLoaded as JSString).toDart),
263263
documentsLoaded = jsObject.documentsLoaded.toDartInt,
264-
totalBytes = jsObject.totalBytes is JSNumber
264+
totalBytes = jsObject.totalBytes.isA<JSNumber>()
265265
? (jsObject.totalBytes as JSNumber).toDartInt
266266
: int.parse((jsObject.totalBytes as JSString).toDart),
267267
totalDocuments = jsObject.totalDocuments.toDartInt,

packages/cloud_firestore/cloud_firestore_web/lib/src/interop/firestore_interop.dart

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -396,16 +396,9 @@ extension FieldPathExtension on FieldPath {
396396
}
397397

398398
@JS('GeoPoint')
399-
@staticInterop
400-
external GeoPointJsImpl get GeoPointConstructor;
401-
402-
@JS('GeoPoint')
403-
@staticInterop
404-
class GeoPointJsImpl {
399+
extension type GeoPointJsImpl._(JSObject _) implements JSObject {
405400
external factory GeoPointJsImpl(JSNumber latitude, JSNumber longitude);
406-
}
407401

408-
extension GeoPointJsImplExtension on GeoPointJsImpl {
409402
/// The latitude of this GeoPoint instance.
410403
external JSNumber get latitude;
411404

@@ -417,19 +410,11 @@ extension GeoPointJsImplExtension on GeoPointJsImpl {
417410
}
418411

419412
@JS('Bytes')
420-
@staticInterop
421-
external BytesJsImpl get BytesConstructor;
422-
423-
@JS('Bytes')
424-
@staticInterop
425-
@anonymous
426-
abstract class BytesJsImpl {
413+
extension type BytesJsImpl(JSObject _) implements JSObject {
427414
external static BytesJsImpl fromBase64JSString(JSString base64);
428415

429416
external static BytesJsImpl fromUint8Array(JSUint8Array list);
430-
}
431417

432-
extension BytesJsImplExtension on BytesJsImpl {
433418
external JSString toBase64();
434419

435420
external JSUint8Array toUint8Array();

packages/cloud_firestore/cloud_firestore_web/lib/src/interop/utils/utils.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import '../firestore.dart';
1212
/// Returns Dart representation from JS Object.
1313
dynamic dartify(dynamic object) {
1414
// Convert JSObject to Dart equivalents directly
15-
if (object is! JSObject) {
15+
if (object.isA<JSObject>()) {
1616
return object;
1717
}
1818

@@ -21,15 +21,15 @@ dynamic dartify(dynamic object) {
2121
if (jsObject.instanceof(DocumentReferenceJsConstructor as JSFunction)) {
2222
return DocumentReference.getInstance(jsObject as DocumentReferenceJsImpl);
2323
}
24-
if (jsObject.instanceof(GeoPointConstructor as JSFunction)) {
24+
if (jsObject.isA<GeoPointJsImpl>()) {
2525
return jsObject;
2626
}
2727
if (jsObject.instanceof(TimestampJsConstructor as JSFunction)) {
2828
final castedJSObject = jsObject as TimestampJsImpl;
2929
return Timestamp(
3030
castedJSObject.seconds.toDartInt, castedJSObject.nanoseconds.toDartInt);
3131
}
32-
if (jsObject.instanceof(BytesConstructor as JSFunction)) {
32+
if (jsObject.isA<BytesJsImpl>()) {
3333
return jsObject as BytesJsImpl;
3434
}
3535

@@ -85,11 +85,12 @@ JSAny? jsify(Object? dartObject) {
8585
return jsifyFieldValue(dartObject);
8686
}
8787

88+
// ignore: invalid_runtime_check_with_js_interop_types
8889
if (dartObject is BytesJsImpl) {
8990
return dartObject as JSAny;
9091
}
9192

92-
// NOTE: if the firestore JS lib is not imported, we'll get a DDC warning here
93+
// ignore: invalid_runtime_check_with_js_interop_types
9394
if (dartObject is GeoPointJsImpl) {
9495
return dartObject as JSAny;
9596
}

packages/cloud_firestore/cloud_firestore_web/lib/src/utils/decode_utility.dart

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import 'package:cloud_firestore_web/src/interop/firestore.dart';
1313
import '../interop/firestore.dart' as firestore_interop;
1414

1515
/// Class containing static utility methods to decode firestore data.
16-
class DecodeUtility {
16+
abstract final class DecodeUtility {
1717
/// Decodes the values on an incoming Map to their proper types.
1818
static Map<String, dynamic>? decodeMapData(
1919
Map<String, dynamic>? data, FirebaseFirestorePlatform firestore) {
@@ -35,14 +35,12 @@ class DecodeUtility {
3535
/// Decodes an incoming value to its proper type.
3636
static dynamic valueDecode(
3737
dynamic value, FirebaseFirestorePlatform firestore) {
38-
if (value is JSObject &&
39-
value.instanceof(GeoPointConstructor as JSFunction)) {
40-
return GeoPoint((value as GeoPointJsImpl).latitude.toDartDouble,
41-
(value as GeoPointJsImpl).longitude.toDartDouble);
38+
if (value.isA<GeoPointJsImpl>()) {
39+
final val = value! as GeoPointJsImpl;
40+
return GeoPoint(val.latitude.toDartDouble, val.longitude.toDartDouble);
4241
} else if (value is DateTime) {
4342
return Timestamp.fromDate(value);
44-
} else if (value is JSObject &&
45-
value.instanceof(BytesConstructor as JSFunction)) {
43+
} else if (value.isA<BytesJsImpl>()) {
4644
return Blob((value as BytesJsImpl).toUint8Array().toDart);
4745
} else if (value is firestore_interop.DocumentReference) {
4846
return (firestore as FirebaseFirestoreWeb).doc(value.path);

packages/cloud_firestore/cloud_firestore_web/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ repository: https://github.com/firebase/flutterfire/tree/master/packages/cloud_f
66
version: 3.12.5
77

88
environment:
9-
sdk: '>=3.2.0 <4.0.0'
9+
sdk: ^3.4.0
1010
flutter: '>=3.3.0'
1111

1212
dependencies:

packages/cloud_functions/cloud_functions_web/lib/interop/functions.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ 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-
if (object is! JSObject) {
92+
if (object.isA<JSObject>()) {
9393
return object;
9494
}
9595

packages/cloud_functions/cloud_functions_web/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ repository: https://github.com/firebase/flutterfire/tree/master/packages/cloud_f
66
version: 4.9.6
77

88
environment:
9-
sdk: '>=3.2.0 <4.0.0'
9+
sdk: ^3.4.0
1010
flutter: '>=3.3.0'
1111

1212
dependencies:

packages/firebase_analytics/firebase_analytics_web/lib/interop/analytics.dart

Lines changed: 1 addition & 1 deletion
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.

packages/firebase_analytics/firebase_analytics_web/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ repository: https://github.com/firebase/flutterfire/tree/master/packages/firebas
55
version: 0.5.7+7
66

77
environment:
8-
sdk: '>=3.2.0 <4.0.0'
8+
sdk: ^3.4.0
99
flutter: '>=3.3.0'
1010

1111
dependencies:

packages/firebase_app_check/firebase_app_check_web/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ homepage: https://github.com/firebase/flutterfire/tree/master/packages/firebase_
44
version: 0.1.2+7
55

66
environment:
7-
sdk: '>=3.2.0 <4.0.0'
7+
sdk: ^3.4.0
88
flutter: '>=3.3.0'
99

1010
dependencies:

packages/firebase_app_installations/firebase_app_installations_web/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ homepage: https://github.com/firebase/flutterfire/tree/master/packages/firebase_
55
repository: https://github.com/firebase/flutterfire/tree/master/packages/firebase_app_installations/firebase_app_installations_web
66

77
environment:
8-
sdk: '>=3.2.0 <4.0.0'
8+
sdk: ^3.4.0
99
flutter: '>=3.3.0'
1010

1111
dependencies:

packages/firebase_auth/firebase_auth/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ false_secrets:
1010
- example/**
1111

1212
environment:
13-
sdk: '>=3.2.0 <4.0.0'
13+
sdk: ^3.4.0
1414
flutter: '>=3.16.0'
1515

1616
dependencies:

packages/firebase_auth/firebase_auth_platform_interface/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ repository: https://github.com/firebase/flutterfire/tree/master/packages/firebas
77
version: 7.3.0
88

99
environment:
10-
sdk: '>=3.2.0 <4.0.0'
10+
sdk: ^3.4.0
1111
flutter: '>=3.16.0'
1212

1313
dependencies:

packages/firebase_auth/firebase_auth_web/lib/firebase_auth_web.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,8 @@ class FirebaseAuthWeb extends FirebaseAuthPlatform {
489489
.setItem(getOriginName(delegate.app.name), origin);
490490
}
491491
} catch (e) {
492-
if (e is auth_interop.AuthError) {
493-
final String code = e.code.toDart;
492+
if ((e as JSObject).isA<auth_interop.AuthError>()) {
493+
final String code = (e as auth_interop.AuthError).code.toDart;
494494
// this catches Firebase Error from web that occurs after hot reloading & hot restarting
495495
if (code != 'auth/emulator-config-failed') {
496496
throw getFirebaseAuthException(e);

packages/firebase_auth/firebase_auth_web/lib/src/firebase_auth_web_recaptcha_verifier_factory.dart

Lines changed: 1 addition & 1 deletion
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
}

packages/firebase_auth/firebase_auth_web/lib/src/interop/auth.dart

Lines changed: 7 additions & 7 deletions
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.

packages/firebase_auth/firebase_auth_web/lib/src/interop/auth_interop.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -650,14 +650,10 @@ extension UserProfileExtension on UserProfile {
650650
external set photoURL(JSString s);
651651
}
652652

653-
@JS()
654-
@staticInterop
655-
abstract class AuthError {}
656-
657653
/// An authentication error.
658654
///
659655
/// See: <https://firebase.google.com/docs/reference/js/firebase.auth.Error>.
660-
extension AuthErrorExtension on AuthError {
656+
extension type AuthError(JSObject _) implements JSObject {
661657
external JSString get code;
662658
external set code(JSString s);
663659
external JSString get message;

packages/firebase_auth/firebase_auth_web/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ repository: https://github.com/firebase/flutterfire/tree/master/packages/firebas
55
version: 5.12.0
66

77
environment:
8-
sdk: '>=3.2.0 <4.0.0'
8+
sdk: ^3.4.0
99
flutter: '>=3.16.0'
1010

1111
dependencies:

packages/firebase_core/firebase_core_web/lib/src/firebase_core_web.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ class FirebaseCoreWeb extends FirebasePlatform {
8787
JSObject? ignored =
8888
globalContext.getProperty('flutterfire_ignore_scripts'.toJS);
8989

90-
if (ignored is Iterable) {
91-
return (ignored! as Iterable)
90+
if (ignored.isA<JSArray>()) {
91+
return (ignored! as JSArray)
92+
.toDart
9293
.map((e) => e.toString())
9394
.toList(growable: false);
9495
}

packages/firebase_core/firebase_core_web/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ repository: https://github.com/firebase/flutterfire/tree/master/packages/firebas
55
version: 2.17.0
66

77
environment:
8-
sdk: '>=3.2.0 <4.0.0'
8+
sdk: ^3.4.0
99
flutter: '>=3.3.0'
1010

1111
dependencies:

packages/firebase_database/firebase_database_web/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version: 0.2.5+7
44
homepage: https://github.com/firebase/flutterfire/tree/master/packages/firebase_database/firebase_database_web
55

66
environment:
7-
sdk: '>=3.2.0 <4.0.0'
7+
sdk: ^3.4.0
88
flutter: '>=3.3.0'
99

1010
dependencies:

packages/firebase_messaging/firebase_messaging_web/lib/firebase_messaging_web.dart

Lines changed: 1 addition & 1 deletion
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
}

0 commit comments

Comments
 (0)