【发布时间】:2021-04-21 20:54:15
【问题描述】:
【问题讨论】:
标签: android firebase android-studio flutter google-cloud-firestore
【问题讨论】:
标签: android firebase android-studio flutter google-cloud-firestore
您的函数是同步的,这意味着一些任务在返回 0 后完成。您可以等待这些任务完成,因为它们相互依赖。
试试这个:
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!");
}
欢迎使用除此之外的任何其他解决方案。
【讨论】:
type 'Future<dynamic>' is not a subtype of type 'num'
Future<num>