问题
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