Reputation: 99
I want to run this, however, it always returns 0. I tried to put the return inside, but it won't return anything.
Upvotes: 0
Views: 105
Reputation: 1609
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.
Upvotes: 2