flutter get user email

i want to get my flutter login form user id into a text box.i used firebase to make authentication. 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. 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. 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. 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. There are other ways to do it too.

Comments

Popular posts from this blog

Meaning of `{}` for return expression

Get current scroll position of ScrollView in React Native

flutter websocket connection issue