我希望未注册的用户单击登录按钮后无法访问下一页,但是我希望弹出窗口中显示一条消息。
我不知道该怎么办,请帮帮我!
我的登录代码:
class LoginManager {
final FirebaseAuth _auth = FirebaseAuth.instance;
final GoogleSignIn googleSignIn = GoogleSignIn();
Future<String> signInWithGoogle() async {
final GoogleSignInAccount googleSignInAccount = await googleSignIn.signIn();
final GoogleSignInAuthentication googleSignInAuthentication =
await googleSignInAccount.authentication;
final AuthCredential credential = GoogleAuthProvider.getCredential(
accessToken: googleSignInAuthentication.accessToken,
idToken: googleSignInAuthentication.idToken,
);
final AuthResult authResult = await _auth.signInWithCredential(credential);
final FirebaseUser user = authResult.user;
assert(!user.isAnonymous);
assert(await user.getIdToken() != null);
final FirebaseUser currentUser = await _auth.currentUser();
assert(user.uid == currentUser.uid);
return("Succesfully login");
}
}
登录按钮的OnTap代码:
onPressed: () {
if(sign.signInWithGoogle() == null){
showDialog(
context: context,
builder: (BuildContext context){
return AlertDialog(
title: new Text("Alert Dialog title"),
content: new Text("Alert Dialog body"),
actions: <Widget>[
// usually buttons at the bottom of the dialog
new FlatButton(
child: new Text("Close"),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
} else {
sign.signInWithGoogle().whenComplete(() {
Navigator.pushReplacement(
context,
new MaterialPageRoute(
builder: (
BuildContext context) => new HomePage()));
});
}
},