目前,我正在尝试将数据写入颤动的设备,但我不确定如何减慢进程并让它加载。
在我的屏幕构建方法的顶部,我在返回脚手架之前有这个。它检查我的可变技能是否正确加载。
@override
Widget build(BuildContext context) {
try {
print(skills.length);
_isLoading = false;
} catch (e) {
_fetchData(context).then((value) {
setState(() {});
});
}
return Scaffold(
问题是它似乎没有等待我的 _fetchData 函数完成。
Future<void> _fetchData(BuildContext context) async {
try {
Provider.of<Skills>(context, listen: false).fetchAndSetSkills().then(
(value) => skills = Provider.of<Skills>(context, listen: false).skills);
Provider.of<Classes>(context, listen: false).fetchAndSetClasses(context);
} catch (e) {
print('Error: $e');
}
}
我得到这个输出
I/flutter (13976): Checking if Can Read Skills
I/flutter (13976): Validate: false
I/flutter (13976): Trying to Write Skills
I/flutter (13976): Writing Skills
I/flutter (13976): Checking if Can Read Skills
I/flutter (13976): Validate: true
I/flutter (13976): Checking if Can Read Skills
I/flutter (13976): Checking if Can Read Skills
I/flutter (13976): Validate: true
I/flutter (13976): Checking if Can Read Skills
I/flutter (13976): Validate: true
I/flutter (13976): Checking if Can Read Skills
I/flutter (13976): Checking if Can Read Skills
I/flutter (13976): Validate: true
I/flutter (13976): 8
我可以做些什么来在功能上减慢我的代码?谢谢!