The app allows the user to sign in using Facebook, but I am having trouble with when the using wants to use a different Facebook account to sign in, this page will only show the continue button. Is there a way for the user to choose to use a different account for signing in? Also, I have not really seem any error in the case for FacebookLoginStatus.error, what are some error handling that should be done to it? I am new to flutter and coding, it will be helpful to point out if anything should be done differently or can be improve on.
onPressed: () async {
final facebookLogin = FacebookLogin();
final result = await facebookLogin.logIn(['email']);
switch (result.status) {
case FacebookLoginStatus.loggedIn:
try{
final token = result.accessToken.token;
AuthCredential credential =
FacebookAuthProvider.getCredential(accessToken: token);
FirebaseUser user = (await _auth.signInWithCredential(credential)).user;
if(user != null){
Navigator.pushReplacementNamed(context, Home.id);
}
} catch(e){
print(e);
}
break;
case FacebookLoginStatus.cancelledByUser:
print('cancelled');
break;
case FacebookLoginStatus.error:
print('error');
break;
}
},
having trouble with when the using wants to use a different Facebook account to sign in, this page will only show the continue button
I use FacebookLogin.logOut()
to disconnect the user, just so the user can use a different account to login.
onPressed: () async {
final facebookLogin = FacebookLogin();
await facebookLogin.logOut(); // disconnect user
final FacebookLoginResult result =
await facebookLogin.logIn(['email', 'public_profile']);
switch (result.status) {
case FacebookLoginStatus.loggedIn:
try{
final token = result.accessToken.token;
AuthCredential credential =
FacebookAuthProvider.getCredential(accessToken: token);
FirebaseUser user = (await _auth.signInWithCredential(credential)).user;
if(user != null){
Navigator.pushReplacementNamed(context, Home.id);
}
} catch(e){
print(e);
}
break;
case FacebookLoginStatus.cancelledByUser:
alertMessage(context, 'cancelled'); // show dialog
break;
case FacebookLoginStatus.error:
alertMessage(context, 'error'); // show dialog
break;
}
},
what are some error handling that should be done to it?
You may prompt user of the login status messages:
void alertMessage(context, String message) {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text("Error"),
content: Text(message),
actions: [
FlatButton(
child: Text(S.of(context).ok),
onPressed: () {
Navigator.of(context).pop();
},
)
],
)
);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With