Hello Guys How are you all? Hope You all are fine. When I was trying to run my flutter app and suddenly I get the following error in my stack track. LateInitializationError: Field ‘[email protected]’ has not been initialized in a flutter. So today Here I come with all possible solutions for this error.
We are providing you all possible solutions to solve this error. let’s start this article without wasting your time.
How LateInitializationError: Field ‘[email protected]’ has not been initialized Error Occurs ?
I am using Firebase Auth and I want to get user detail on intialize but its give me following error.
The following LateError was thrown building UserProfile(dirty, state: _UserProfileState#752a9): LateInitializationError: Field '[email protected]' has not been initialized."
Here is my code
@override
void initState() {
super.initState();
_getUserData();
}
void _getUserData() async {
_loginUser = FirebaseAuth.instance.currentUser!;
try {
_userData = await FirebaseFirestore.instance
.collection('users')
.doc(users.uid)
.get();
} catch (e) {
print("something went wrong");
}
}
How to Solve LateInitializationError: Field ‘[email protected]’ has not been initialized Error?
- How to Solve LateInitializationError: Field '[email protected]' has not been initialized Error?
To Solve LateInitializationError: Field '[email protected]' has not been initialized simply put whenComplete() to your _getUserData() method and when this process will be completed just put empty setState() there It will rebuild the widget tree with the new values.
- LateInitializationError: Field '[email protected]' has not been initialized
To Solve LateInitializationError: Field '[email protected]' has not been initialized simply put whenComplete() to your _getUserData() method and when this process will be completed just put empty setState() there It will rebuild the widget tree with the new values.
Solution 1
To solve this error simply put whenComplete() to your _getUserData() method and when this process will be completed just put empty setState() there It will rebuild the widget tree with the new values.
void initState() {
super.initState();
_initUser().whenComplete((){
setState(() {});
});
}
Summery
So, It’s All About This Error. I hope this tutorial helps you to Solve your error. Please Comment Below if You stucks anywhere with my code. And please comment below on which solution worked for you. Thank You.
Leave a Reply