【发布时间】:2021-09-18 12:39:20
【问题描述】:
我想让用户自己设置密码,并通过点击使用谷歌注册来确认密码。该按钮只会将他们的谷歌帐户电子邮件作为电子邮件,用户必须自己设置密码。
注册屏幕 -
SignInButton(
onPressed: () {
signInWithGoogle();
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => TasksScreen(),
),
);
},
btnText: 'Sign up with Google',
btnTextColor: Colors.blue,
buttonType: ButtonType.google,
buttonSize: ButtonSize.medium,
),
],
),
signInWithGoogle -
Future<UserCredential> signInWithGoogle() async {
// Trigger the authentication flow
final GoogleSignInAccount googleUser = await GoogleSignIn().signIn();
// Obtain the auth details from the request
final GoogleSignInAuthentication googleAuth = await googleUser.authentication;
// Create a new credential
final credential = GoogleAuthProvider.credential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
// Once signed in, return the UserCredential
return await FirebaseAuth.instance.signInWithCredential(credential);
}
【问题讨论】:
-
附上代码而不是代码图像是击球手。
标签: firebase flutter firebase-authentication google-authentication