【发布时间】:2019-11-10 07:20:29
【问题描述】:
我不明白为什么我在未来的构建器中总是得到空返回,而我确定应该有一个值
//global variables
Map<String,bool> students;
List<String> studentsList ;
List<bool> studentsCheck ;
FutureBuilder(
future: GetInfoFromBackEnd(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
return snapshot.hasData?
CustomScrollView(....some not important widgets here....):CircularProgressIndicator();
},)
Future GetInfoFromBackEnd() async {
students = {
'this info should be taken from backend0':false,
'this info should be taken from backend0':false,
'this info should be taken from backend0':false,
'this info should be taken from backend0':false,
'this info should be taken from backend0':false,
};
studentsList = students.keys;
studentsCheck = students.values;
return students;
}
我对此代码有一个解决方法,但我需要了解为什么会这样以及发生了什么
【问题讨论】:
-
什么是空?
snapshot.data? -
我用了你的例子,既不是快照,也不是 hasData 为空。
-
顺便说一句,如果你想在地图中使用模拟数据进行测试,你至少需要有不同的键。否则,您最终只会在地图中得到一个元素。我会通过向 AsyncSnapshot
-
@pskink 是的,它是快照数据
-
Marc 好的,请稍等,我将编辑代码并尝试