I just want to return the value of each condition and use it as the value of the function.
Here is my code for it.
var getStuff = chechIfExisting();
chechIfExisting() async {
var isExisting = await FirebaseFirestore.instance
.collection('merchants')
.doc(userUid)
.get();
if (isExisting.exists) {
return 'exists';
}
if (!isExisting.exists) {
return 'nope';
} else {
return 'error';
}
}
and I am not using any Stateless and Stateful Widget since this file contains only the widgets such as appbar/mydrawer. I wanted to use the 'getStuff' variable in a if statement under the myDrawer Widget, since I want to dynamically check if the the data that I am fetching is existing or not.
myDrawer(BuildContext context) {
print('getStuff');
// only prints 'Instance of 'Future<String>' and does not return the value.
}
I want to be able to use the 'getStuff' variable as
myDrawer(BuildContext context) {
if(getStuff == 'exists'){
// code here
}
Any helps/ideas on how to solve this are appreciated!
with this line:
You're not waiting for the method to finishes executing, since it's a
Future
, not using eitherawait
/async
orthen
to resolve values after theFuture
finishes will get you thatgetStuff()
is a type ofInstance of 'Future<String>
, before the running of themyDrawer
function, you need either to:or:
then you can run the
myDrawer
method and get it working fine