在Flutter的启动画面期间加载数据 [英] Load Data during Splash Screen in Flutter

查看:163
本文介绍了在Flutter的启动画面期间加载数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道在闪屏中可见初始屏幕时,有什么方法可以执行任务.我知道如何在闪屏中添加闪屏,但不知道在闪屏可见期间如何执行后台操作.我在互联网上找不到任何东西,请帮忙.

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.

推荐答案

是的,可以.实际上,main()函数可以标记为async,因此您可以在main()方法主体中运行runApp(...)之前做任何需要做的事情,甚至是异步进行的 .这样,在调用runApp(...)之前,将显示启动屏幕,直到检索到异步结果为止.例如:

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));
}

这篇关于在Flutter的启动画面期间加载数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆