Your function is synchronous this means some of tasks are finished after it returns 0. You may wait for those tasks to finish because they are dependent each other.
Try this:
Future<num> getRating(foodId){
num a = 0;
num b = 0;
num c;
var user = await FirebaseAuth.instance.currentUser();
if(user != null)
{
var docs = await Firestore.instance.collection('users').getDocuments();
if(docs != null){
if(docs.document[7].data[foodId] != null){
// TODO
}
if(b != 0) {
c = a / b;
retrun c;
}
return 0;
}
return 0; // Or throw exception when docs is null (this according to your need)
}
throw Exception("User unauthenticated!");
}
Welcome to any other solution other than that.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.