简体   繁体   English

扑通用户电子邮件

[英]flutter get user email

i want to get my flutter login form user id into a text box.i used firebase to make authentication. 我想将Flutter登录表单用户ID放入文本框。我使用Firebase进行身份验证。 i wrote a method to get user email. 我写了一种获取用户电子邮件的方法。

  _getUserEmail(){

    FutureBuilder<FirebaseUser>(
      future: FirebaseAuth.instance.currentUser(),
      builder: (BuildContext context, AsyncSnapshot<FirebaseUser> snapshot) {
        if (snapshot.connectionState == ConnectionState.done) {
          return new Text(snapshot.data.email);
        }
        else {
          return new Text('Loading...');
        }
      },
    );
  }

i want to get this user email into my flutter textbox view initial value. 我想将此用户电子邮件发送到我的Flutter文本框视图初始值。 This is my flutter textbox. 这是我扑朔迷离的文本框。

ListTile(
       leading: Icon(Icons.info),
       title: TextFormField(
        decoration: InputDecoration(
              labelText: 'Enter Your name'
         ),
          initialValue: _getUserEmail(),
           onSaved: (val) => item.name = val,
           validator: (val) => val == "" ? val : null,
         ),
        ),

i want to get my email into ListTile initial value. 我想让我的电子邮件进入ListTile的初始值。 can anyone help me? 谁能帮我?

Perhaps not a direct answer to your question. 也许不是您问题的直接答案。 But using a form with validation for async authentication requires particular management of the validators to handle the async result. 但是,使用带有验证的表单进行异步身份验证需要对验证器进行特殊管理,以处理异步结果。 I but together a demo of how to manage the validators. 我将一起演示如何管理验证器的演示。 The demo simulates the async call, so you would have to implement the firebase auth for your particular app. 该演示模拟了异步调用,因此您必须为特定应用实现firebase auth。 Might be a useful reference if still having problems. 如果仍然有问题,可能是有用的参考。

在此处输入图片说明

You can find source code here 您可以在此处找到源代码

Edit: I created an example showing how to preload the form by inserting a widget that makes an async call. 编辑:我创建了一个示例,展示了如何通过插入进行异步调用的小部件来预加载表单。 在此处输入图片说明

I also got it to work using a FutureBuilder too, but this seemed cleaner. 我也让它也可以使用FutureBuilder来工作,但这看起来更干净。 There are other ways to do it too. 还有其他方法可以做到这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM