与Google Auth和用户打交道

时间:2018-07-16 22:14:11

标签: firebase dart firebase-authentication flutter

我有代码,当用户未登录时,它会显示“您尚未登录”作为字幕,然后在登录后显示用户名,但是如果我按“注销”按钮,文本也不会更改以注销如果我关闭该应用程序并重新启动它。你能帮助我吗。这是登录和注销的代码。

new ListTile(
          title: new Text("Log In"),
          leading: new Icon(Icons.account_box),
          onTap: () => _signIn()
              .then((FirebaseUser user) => print(user))
              .catchError((e) => print(e)),
          subtitle: StreamBuilder(
            stream: FirebaseAuth.instance.onAuthStateChanged,
            builder: (BuildContext context, AsyncSnapshot<FirebaseUser> snapshot) {
              var username ='';
              if (snapshot.connectionState == ConnectionState.waiting) {
                return Text('loading');
              } else if (!snapshot.hasData) {
                username= 'you are not logged in';
                return Text(username);
              } else {
                username = snapshot.data.displayName;
                return Text(username);
              }
            },
          ),
        ),
        new ListTile(
          title: new Text("Log Out"),
          leading: new Icon(Icons.account_circle),
          onTap: () => _signOut(),
        ),

当用户登录并成为用户名时,我希望字幕中的文本更改,并且当用户注销时,您未登录的文本更改(这是我想要的,但是如果您可以在用户已经登录时按下登录磁贴时显示小吃条,而在用户已经退出时按小吃栏显示) 谢谢

0 个答案:

没有答案
相关问题