最好的等待方式 [Flutter]

问题描述

目前,我正在尝试将数据写入带有抖动的设备,但我不确定如何减慢进程并让它加载。

在我的屏幕构建方法的顶部,我在返回我的脚手架之前有这个。它会检查我的可变技能是否正确加载。

@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

我有什么建议可以在功能上减慢我的代码? 谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...