行动后生成颤振路线? [英] Generating Flutter route after action?

查看:23
本文介绍了行动后生成颤振路线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在成功登录后自动返回我的菜单屏幕,但在生成小部件构建和/或上下文时遇到问题.我在无状态小部件中执行此操作.这是我的代码.我想在最后一个打印语句之后调用路由...

I'm trying to automatically route back to my menu screen after a successful login and I'm having trouble generating a Widget build and/or context. I'm doing this in a Stateless Widget. Here is my code. I would like to call route after the last print statement...

Future<Null> _handleSignIn() async {
    try {
      await _googleSignIn.disconnect();
      GoogleSignInAccount googleUser = await _googleSignIn.signIn();
      GoogleSignInAuthentication googleAuth = await googleUser.authentication;

      print(googleAuth.idToken);

      await FirebaseAuth.instance.signInWithGoogle(idToken: googleAuth.idToken, accessToken: googleAuth.accessToken);


    } catch (error) {
      print(error);
    }
    print("Let's Do This");
    print(_googleSignIn.currentUser.displayName);
    print(FirebaseAuth.instance.currentUser);
  }

推荐答案

根据我从您的问题中了解到的,您基本上需要设置登录按钮,以便在成功登录后将用户重定向到您希望他们到达的任何位置.

From what I understand from your question you basically need to setup your sign in button to redirect the users to wherever you want them to be after a successful sign in.

您可以按如下方式设置 onPressed 调用,从这里开始应该没问题:

You can setup your onPressed call as follows, and you should be fine from here:

onPressed: () {_handleSignIn().whenComplete( ()=>Navigator.of(context).pushNamed("/MyHome"));
                      }

注意你不能在你的构建方法之外使用 Navigator,因此你总是需要在你的小部件中处理导航部分.查看对此答案的评论.

Note that you can not use Navigator outside your build method, hence you always need to handle the navigation parts within your widgets. Check the comment on this answer.

这篇关于行动后生成颤振路线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆