Google登录后如何过渡到另一个屏幕?

时间:2019-02-02 11:48:12

标签: android dart flutter google-signin

我正在编程,并想使用Google登录进行手势处理。我需要在哪里将Enter设置到另一个屏幕?

GoogleSignIn _googleSignIn = GoogleSignIn(   scopes: [
    'email',
    'https://www.googleapis.com/auth/contacts.readonly',   ], );

class LoginScreen extends StatefulWidget {   @override  
_LoginScreenState createState() => _LoginScreenState(); }

class _LoginScreenState extends State<LoginScreen> {

  Future<void> _handleSignIn() async {
    try {
      await _googleSignIn.signIn();
      Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => HomeScreen()));
    } catch (error) {
      print(error);
    }   }

  @override   Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        resizeToAvoidBottomPadding: false,
        body: ListView(children: <Widget>[
          Container(
            child: Form(
                autovalidate: true,
                child: Column(
                    children: <Widget>[
                      ButtonTheme(
                        minWidth: double.infinity,
                        height: 55.0,
                        child: RaisedButton(
                          shape: new RoundedRectangleBorder(
                              borderRadius: new BorderRadius.circular(30.0),
                              side: BorderSide(width: 1, color: Colors.red)),
                          color: Colors.white,
                          onPressed: _handleSignIn
                          //    Navigator.of(context).pushReplacementNamed('/home_screen');
                          ,
                          child: Text(
                            'Sign in with Google',
                            style: TextStyle(
                              color: Colors.red,
                              fontSize: 20,
                            ),
                          ),
                        ),
                      ),
                    ])),
          )
        ]),
      ),
    );   } }

如果我单击按钮,应该会出现google登录,并且添加帐户后已进入另一个屏幕。 但是,当我单击按钮时,Google登录会打开,并且在添加帐户后不会出现任何变化。

1 个答案:

答案 0 :(得分:0)

您的Navigator pushReplacement实现错误。试试:Navigator.of(context).pushReplacement(MaterialPageRoute(builder: (context)=> HomeScreen()));