且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何正确地等到飞镖的未来完成

更新时间:2022-04-07 23:12:57

您应该在initState()函数中从数据库中获取日期,然后必须修改窗口小部件生成器以使用FutureBuilder,这是一个示例:

You Should fetch your date from the database in the initState() function, then you have to modify your widget builder to use FutureBuilder, here's an example:

Widget build(BuildContext context) {
return FutureBuilder(
    future: getProfile(),
    builder: (BuildContext context, AsyncSnapshot<SharedPreferences> snapshot) {
      if(snapshot.connectionState == ConnectionState.done){
        return new MaterialApp();
      }
    }
  )
}

请注意,您可以将AsyncSnapshot<SharedPreferences>替换为Future函数返回的类型.

note that you can replace AsyncSnapshot<SharedPreferences> with the type your Future function returns.