Load Data during Splash Screen in Flutter

北慕城南 提交于 2020-07-21 03:40:26

问题


I need to know is there any way to perform a task during splash screen is visible in flutter. I know how to add splash screen in flutter but I don't know how to perform background operations during splash screen is visible. I can't find anything on the internet, please help.


回答1:


Yes, yes you can. The main() function can actually be tagged as async, so you can do whatever you need to do before running runApp(...) in the main() method body, even asynchronously. This way, the splash screen will be shown until your asynchronous result is retrieved, before calling runApp(...). For example:

Future<void> main() async {

// Do whatever you need to do here
final home = await setHomeWidgetDependingOnLoginStatus();

return runApp(MyApp(home: home));
}


来源:https://stackoverflow.com/questions/58615545/load-data-during-splash-screen-in-flutter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!