更新flutter中变量的值

时间:2018-07-16 17:12:18

标签: firebase authentication 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(),
        ),

我想在ontap函数的下一个图块中使用该变量

0 个答案:

没有答案