Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
[firebase_auth] add type parameters for invokeMethod and bump min flu…
Browse files Browse the repository at this point in the history
…tter version to 1.5.0 (#1655)
  • Loading branch information
Chris Yang committed May 30, 2019
1 parent c4970d8 commit 9baf6ec
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 102 deletions.
7 changes: 7 additions & 0 deletions packages/firebase_auth/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.11.1+3

* Add missing template type parameter to `invokeMethod` calls.
* Bump minimum Flutter version to 1.5.0.
* Replace invokeMethod with invokeMapMethod wherever necessary.
* FirebaseUser private constructor takes `Map<String, dynamic>` instead of `Map<dynamic, dynamic>`.

## 0.11.1+2

* Suppress deprecation warning for BinaryMessages. See: https://github.com/flutter/flutter/issues/33446
Expand Down
83 changes: 25 additions & 58 deletions packages/firebase_auth/lib/src/firebase_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,14 @@ class FirebaseAuth {

StreamController<FirebaseUser> controller;
controller = StreamController<FirebaseUser>.broadcast(onListen: () {
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
_handle = channel.invokeMethod('startListeningAuthState',
_handle = channel.invokeMethod<int>('startListeningAuthState',
<String, String>{"app": app.name}).then<int>((dynamic v) => v);
_handle.then((int handle) {
_authStateChangedControllers[handle] = controller;
});
}, onCancel: () {
_handle.then((int handle) async {
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
await channel.invokeMethod("stopListeningAuthState",
await channel.invokeMethod<void>("stopListeningAuthState",
<String, dynamic>{"id": handle, "app": app.name});
_authStateChangedControllers.remove(handle);
});
Expand All @@ -78,11 +72,9 @@ class FirebaseAuth {
/// Errors:
/// • `ERROR_OPERATION_NOT_ALLOWED` - Indicates that Anonymous accounts are not enabled.
Future<FirebaseUser> signInAnonymously() async {
final Map<dynamic, dynamic> data = await channel
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
.invokeMethod('signInAnonymously', <String, String>{"app": app.name});
final Map<String, dynamic> data = await channel
.invokeMapMethod<String, dynamic>(
'signInAnonymously', <String, String>{"app": app.name});
final FirebaseUser currentUser = FirebaseUser._(data, app);
return currentUser;
}
Expand All @@ -102,10 +94,8 @@ class FirebaseAuth {
}) async {
assert(email != null);
assert(password != null);
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
final Map<dynamic, dynamic> data = await channel.invokeMethod(
final Map<String, dynamic> data =
await channel.invokeMapMethod<String, dynamic>(
'createUserWithEmailAndPassword',
<String, String>{'email': email, 'password': password, 'app': app.name},
);
Expand All @@ -126,14 +116,10 @@ class FirebaseAuth {
@required String email,
}) async {
assert(email != null);
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
final List<dynamic> providers = await channel.invokeMethod(
return await channel.invokeListMethod<String>(
'fetchSignInMethodsForEmail',
<String, String>{'email': email, 'app': app.name},
);
return providers?.cast<String>();
}

/// Triggers the Firebase Authentication backend to send a password-reset
Expand All @@ -147,10 +133,7 @@ class FirebaseAuth {
@required String email,
}) async {
assert(email != null);
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
return await channel.invokeMethod(
return await channel.invokeMethod<void>(
'sendPasswordResetEmail',
<String, String>{'email': email, 'app': app.name},
);
Expand All @@ -173,10 +156,7 @@ class FirebaseAuth {
assert(androidPackageName != null);
assert(androidInstallIfNotAvailable != null);
assert(androidMinimumVersion != null);
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
await channel.invokeMethod(
await channel.invokeMethod<void>(
'sendLinkToEmail',
<String, dynamic>{
'email': email,
Expand All @@ -193,7 +173,7 @@ class FirebaseAuth {

/// Checks if link is an email sign-in link.
Future<bool> isSignInWithEmailLink(String link) async {
return await channel.invokeMethod(
return await channel.invokeMethod<bool>(
'isSignInWithEmailLink',
<String, String>{'link': link, 'app': app.name},
);
Expand All @@ -209,7 +189,8 @@ class FirebaseAuth {
/// • `ERROR_INVALID` - Indicates the email address is invalid.
Future<FirebaseUser> signInWithEmailAndLink(
{String email, String link}) async {
final Map<dynamic, dynamic> data = await channel.invokeMethod(
final Map<String, dynamic> data =
await channel.invokeMapMethod<String, dynamic>(
'signInWithEmailAndLink',
<String, dynamic>{
'app': app.name,
Expand Down Expand Up @@ -272,10 +253,8 @@ class FirebaseAuth {
/// This can only occur when using [EmailAuthProvider.getCredentialWithLink] to obtain the credential.
Future<FirebaseUser> signInWithCredential(AuthCredential credential) async {
assert(credential != null);
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
final Map<dynamic, dynamic> data = await channel.invokeMethod(
final Map<String, dynamic> data =
await channel.invokeMapMethod<String, dynamic>(
'signInWithCredential',
<String, dynamic>{
'app': app.name,
Expand Down Expand Up @@ -356,10 +335,7 @@ class FirebaseAuth {
'app': app.name,
};

// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
await channel.invokeMethod('verifyPhoneNumber', params);
await channel.invokeMethod<void>('verifyPhoneNumber', params);
}

/// Tries to sign in a user with a given Custom Token [token].
Expand All @@ -382,10 +358,8 @@ class FirebaseAuth {
/// Ensure your app's SHA1 is correct in the Firebase console.
Future<FirebaseUser> signInWithCustomToken({@required String token}) async {
assert(token != null);
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
final Map<dynamic, dynamic> data = await channel.invokeMethod(
final Map<String, dynamic> data =
await channel.invokeMapMethod<String, dynamic>(
'signInWithCustomToken',
<String, String>{'token': token, 'app': app.name},
);
Expand All @@ -399,19 +373,14 @@ class FirebaseAuth {
/// the [onAuthStateChanged] stream.
Future<void> signOut() async {
return await channel
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
.invokeMethod("signOut", <String, String>{'app': app.name});
.invokeMethod<void>("signOut", <String, String>{'app': app.name});
}

/// Returns the currently signed-in [FirebaseUser] or [null] if there is none.
Future<FirebaseUser> currentUser() async {
final Map<dynamic, dynamic> data = await channel
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
.invokeMethod("currentUser", <String, String>{'app': app.name});
final Map<String, dynamic> data = await channel
.invokeMapMethod<String, dynamic>(
"currentUser", <String, String>{'app': app.name});
final FirebaseUser currentUser =
data == null ? null : FirebaseUser._(data, app);
return currentUser;
Expand All @@ -422,10 +391,8 @@ class FirebaseAuth {
/// code should follow the conventions defined by the IETF in BCP47.
Future<void> setLanguageCode(String language) async {
assert(language != null);
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
await FirebaseAuth.channel.invokeMethod('setLanguageCode', <String, String>{
await FirebaseAuth.channel
.invokeMethod<void>('setLanguageCode', <String, String>{
'language': language,
'app': app.name,
});
Expand Down Expand Up @@ -479,7 +446,7 @@ class FirebaseAuth {
final int id = call.arguments["id"];

final FirebaseUser currentUser =
data != null ? FirebaseUser._(data, app) : null;
data != null ? FirebaseUser._(data.cast<String, dynamic>(), app) : null;
_authStateChangedControllers[id].add(currentUser);
}
}
53 changes: 12 additions & 41 deletions packages/firebase_auth/lib/src/firebase_user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ part of firebase_auth;

/// Represents a user.
class FirebaseUser extends UserInfo {
FirebaseUser._(Map<dynamic, dynamic> data, FirebaseApp app)
FirebaseUser._(Map<String, dynamic> data, FirebaseApp app)
: providerData = data['providerData']
.map<UserInfo>((dynamic item) => UserInfo._(item, app))
.toList(),
Expand Down Expand Up @@ -35,10 +35,7 @@ class FirebaseUser extends UserInfo {
/// Completes with an error if the user is signed out.
Future<String> getIdToken({bool refresh = false}) async {
return await FirebaseAuth.channel
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
.invokeMethod('getIdToken', <String, dynamic>{
.invokeMethod<String>('getIdToken', <String, dynamic>{
'refresh': refresh,
'app': _app.name,
});
Expand All @@ -63,10 +60,8 @@ class FirebaseUser extends UserInfo {
/// This can only occur when using [EmailAuthProvider.getCredentialWithLink] to obtain the credential.
Future<FirebaseUser> linkWithCredential(AuthCredential credential) async {
assert(credential != null);
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
final Map<dynamic, dynamic> data = await FirebaseAuth.channel.invokeMethod(
final Map<String, dynamic> data =
await FirebaseAuth.channel.invokeMapMethod<String, dynamic>(
'linkWithCredential',
<String, dynamic>{
'app': _app.name,
Expand All @@ -80,30 +75,21 @@ class FirebaseUser extends UserInfo {

/// Initiates email verification for the user.
Future<void> sendEmailVerification() async {
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
await FirebaseAuth.channel.invokeMethod(
await FirebaseAuth.channel.invokeMethod<void>(
'sendEmailVerification', <String, String>{'app': _app.name});
}

/// Manually refreshes the data of the current user (for example,
/// attached providers, display name, and so on).
Future<void> reload() async {
await FirebaseAuth.channel
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
.invokeMethod('reload', <String, String>{'app': _app.name});
.invokeMethod<void>('reload', <String, String>{'app': _app.name});
}

/// Deletes the user record from your Firebase project's database.
Future<void> delete() async {
await FirebaseAuth.channel
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
.invokeMethod('delete', <String, String>{'app': _app.name});
.invokeMethod<void>('delete', <String, String>{'app': _app.name});
}

/// Updates the email address of the user.
Expand All @@ -124,10 +110,7 @@ class FirebaseUser extends UserInfo {
/// • `ERROR_OPERATION_NOT_ALLOWED` - Indicates that Email & Password accounts are not enabled.
Future<void> updateEmail(String email) async {
assert(email != null);
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
return await FirebaseAuth.channel.invokeMethod(
return await FirebaseAuth.channel.invokeMethod<void>(
'updateEmail',
<String, String>{'email': email, 'app': _app.name},
);
Expand Down Expand Up @@ -170,10 +153,7 @@ class FirebaseUser extends UserInfo {
/// • `ERROR_OPERATION_NOT_ALLOWED` - Indicates that Email & Password accounts are not enabled.
Future<void> updatePassword(String password) async {
assert(password != null);
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
return await FirebaseAuth.channel.invokeMethod(
return await FirebaseAuth.channel.invokeMethod<void>(
'updatePassword',
<String, String>{'password': password, 'app': _app.name},
);
Expand All @@ -188,10 +168,7 @@ class FirebaseUser extends UserInfo {
assert(userUpdateInfo != null);
final Map<String, String> data = userUpdateInfo._updateData;
data['app'] = _app.name;
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
return await FirebaseAuth.channel.invokeMethod(
return await FirebaseAuth.channel.invokeMethod<void>(
'updateProfile',
data,
);
Expand All @@ -216,10 +193,7 @@ class FirebaseUser extends UserInfo {
Future<FirebaseUser> reauthenticateWithCredential(
AuthCredential credential) async {
assert(credential != null);
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
await FirebaseAuth.channel.invokeMethod(
await FirebaseAuth.channel.invokeMethod<void>(
'reauthenticateWithCredential',
<String, dynamic>{
'app': _app.name,
Expand All @@ -245,10 +219,7 @@ class FirebaseUser extends UserInfo {
/// • `ERROR_REQUIRES_RECENT_LOGIN` - If the user's last sign-in time does not meet the security threshold. Use reauthenticate methods to resolve.
Future<void> unlinkFromProvider(String provider) async {
assert(provider != null);
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
return await FirebaseAuth.channel.invokeMethod(
return await FirebaseAuth.channel.invokeMethod<void>(
'unlinkFromProvider',
<String, String>{'provider': provider, 'app': _app.name},
);
Expand Down
2 changes: 1 addition & 1 deletion packages/firebase_auth/lib/src/user_metadata.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ part of firebase_auth;
class FirebaseUserMetadata {
FirebaseUserMetadata._(this._data);

final Map<dynamic, dynamic> _data;
final Map<String, dynamic> _data;

int get creationTimestamp => _data['creationTimestamp'];

Expand Down
4 changes: 2 additions & 2 deletions packages/firebase_auth/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: Flutter plugin for Firebase Auth, enabling Android and iOS
like Google, Facebook and Twitter.
author: Flutter Team <flutter-dev@googlegroups.com>
homepage: https://github.com/flutter/plugins/tree/master/packages/firebase_auth
version: "0.11.1+2"
version: "0.11.1+3"

flutter:
plugin:
Expand All @@ -30,4 +30,4 @@ dev_dependencies:

environment:
sdk: ">=2.0.0-dev.28.0 <3.0.0"
flutter: ">=0.1.4 <2.0.0"
flutter: ">=1.5.0 <2.0.0"

0 comments on commit 9baf6ec

Please sign in to comment.