问题
I have implemented Google sign-in option in my project for users to sign in. The app is launching properly and I'm able to click on the google sign in, it is also displaying the google accounts available in my mobile but when I click on any account it is not moving to another page and throwing this error.
Here's my code:
final FirebaseAuth _firebaseAuth = FirebaseAuth.instance;
final GoogleSignIn _googleSignIn = new GoogleSignIn();
Future<FirebaseUser> _signIn(BuildContext context) async {
Scaffold.of(context).showSnackBar(new SnackBar(
content: new Text('Sign in'),
));
final GoogleSignInAccount googleUser = await _googleSignIn.signIn();
final GoogleSignInAuthentication googleAuth = await googleUser.authentication;
final AuthCredential credential = GoogleAuthProvider.getCredential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
FirebaseUser userDetails = (await _firebaseAuth.signInWithCredential(credential)).user;
ProviderDetails providerInfo = new ProviderDetails(userDetails.providerId);
List<ProviderDetails> providerData = new List<ProviderDetails>();
providerData.add(providerInfo);
UserDetails details = new UserDetails(
userDetails.providerId,
userDetails.displayName,
userDetails.photoUrl,
userDetails.email,
providerData,
);
Navigator.push(
context,
new MaterialPageRoute(
builder: (context) => new Profile(detailsUser: details),
),
);
return userDetails;
}
Error:
W/ActivityThread(17894): handleWindowVisibility: no activity for token android.os.BinderProxy@19a997e
I/flutter (17894): PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null)
W/ActivityThread(17894): handleWindowVisibility: no activity for token android.os.BinderProxy@294d2d5
I/flutter (17894): PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null)
D/FlutterView(17894): Detaching from a FlutterEngine: io.flutter.embedding.engine.FlutterEngine@a62a191
this is my profile page code please do check
Code: class Profile extends StatelessWidget { final UserDetails detailsUser;
Profile({Key key, @required this.detailsUser}) : super(key: key);
@override Widget build(BuildContext context) { final GoogleSignIn _gSignIn = GoogleSignIn();
return Scaffold(
appBar: AppBar(
title: Text(detailsUser.userName),
automaticallyImplyLeading: false,
actions: <Widget>[
IconButton(
icon: Icon(
FontAwesomeIcons.signOutAlt,
size: 20.0,
color: Colors.white,
),
onPressed: (){
_gSignIn.signOut();
print('Signed out');
Navigator.pop(context);
},
),
],
),
body:Center(child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
CircleAvatar(
backgroundImage:NetworkImage(detailsUser.photoUrl),
radius: 50.0,
),
SizedBox(height:10.0),
Text(
"Name : " + detailsUser.userName,
style: TextStyle(fontWeight: FontWeight.bold, color: Colors.black,fontSize: 20.0),
),
SizedBox(height:10.0),
Text(
"Email : " + detailsUser.userEmail,
style: TextStyle(fontWeight: FontWeight.bold, color: Colors.black,fontSize: 20.0),
),
SizedBox(height:10.0),
Text(
"Provider : " + detailsUser.providerDetails,
style: TextStyle(fontWeight: FontWeight.bold, color: Colors.black,fontSize: 20.0),
),
来源:https://stackoverflow.com/questions/59455961/error-while-doing-firebase-google-sign-in