检查应用程序是否首次在Flutter上运行 [英] Check if an application is on its first run with Flutter
本文介绍了检查应用程序是否首次在Flutter上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
基本上,我想拥有一个屏幕/视图,该屏幕/视图将在用户首次打开应用程序时打开。这将是登录屏幕类型的事物。
Basically, I want to have a screen/view that will open when the user opens up the app for the first time. This will be a login screen type of thing.
推荐答案
使用共享的首选项包。您可以使用 FutureBuilder
进行阅读,并且可以检查是否存在名为 welcome
的布尔值。这是我代码中的实现:
Use Shared Preferences Package. You can read it with FutureBuilder
, and you can check if there is a bool named welcome
for example. This is the implementation I have in my code:
return new FutureBuilder<SharedPreferences>(
future: SharedPreferences.getInstance(),
builder:
(BuildContext context, AsyncSnapshot<SharedPreferences> snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.none:
case ConnectionState.waiting:
return new LoadingScreen();
default:
if (!snapshot.hasError) {
@ToDo("Return a welcome screen")
return snapshot.data.getBool("welcome") != null
? new MainView()
: new LoadingScreen();
} else {
return new ErrorScreen(error: snapshot.error);
}
}
},
);
这篇关于检查应用程序是否首次在Flutter上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文