可在仿真器中运行,但不能在真实设备中运行

时间:2020-04-17 09:32:35

标签: flutter google-login

此代码可在仿真器上正常工作:

  1. 登录到Google
  2. 选择帐户
  3. 自动转到下一页

但是在真实设备中:

  1. 登录到Google
  2. 选择帐户
  3. 不要转到下一页

    class LoginPageWidget extends StatelessWidget {
    final GoogleSignIn _googleSignIn = GoogleSignIn();
    final FirebaseAuth _auth = FirebaseAuth.instance;
    Future<FirebaseUser> _handleSignIn() async {
    FirebaseUser user;
    bool isSignedIn = await _googleSignIn.isSignedIn();
    if (isSignedIn) {user = await _auth.currentUser();
    } else {
      final GoogleSignInAccount googleUser = await _googleSignIn.signIn();
      final GoogleSignInAuthentication googleAuth =
      await googleUser.authentication;
      final AuthCredential credential = GoogleAuthProvider.getCredential(
          accessToken: googleAuth.accessToken, idToken: googleAuth.idToken);
      user = (await _auth.signInWithCredential(credential)).user;}
    return user;}
    void onGoogleSignIn(BuildContext context) async {
    FirebaseUser user = await _handleSignIn();
    Navigator.push(context,MaterialPageRoute(builder: (context) => Home(user, _googleSignIn)));}
    @override
    Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        padding: EdgeInsets.all(50),
        child: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: <Widget>[
              Hero(tag: 'logo',
                  child: Container(width: 120.0,
                    child: Image.asset("assets/logo.png"),)),
              SizedBox(height: 40,),
              FittedBox(fit: BoxFit.fitWidth,
                child: FlatButton(
                  shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
                  onPressed: () {onGoogleSignIn(context);},
                  color: Colors.blueAccent,
                  child: Padding(
                    padding: EdgeInsets.all(10),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: <Widget>[
                        Image(image: AssetImage("assets/google_logo.png"), height: 35.0),
                        SizedBox(width: 15),
                        Text('Entrar com Google',style: TextStyle(color: Colors.white, fontSize:20
    ),),],),),),),],),),),);}}
    

Print Screen of Emulator and Real Device

0 个答案:

没有答案