If I have statefull widget with initial satate variable called value ,Like this :
@override
void initState() {
thisDayActivity = dataBase.getDetails(widget.courseId, widget.actId);
value = 0.0;
super.initState();
}
thisDayActivity is future list comming from sqflite database, I want check if the list is empty the value variable equal to 0,else value equale some data in future list.
I tride this but don't work :
@override
void initState() {
thisDayActivity = dataBase.getDetails(widget.courseId, widget.actId);
if (thisDayActivity == []) {
value = 0.0;
} else {
value = thisDayActivity[0]['digree'].toDouble();
}
super.initState();
}
How can I solve this?
your method is not working since you are reading a value from a future function, what you need to do is to use the
then
method to achieve your goal like this: