[英]show an alert box when the app is installed for the first time using shared preferences + flutter + dart
im developing an android app,我正在开发一个 android 应用程序,
Where i want an alert box to pop up only when the user installs the app for the first time using shared preferences.我希望仅当用户使用共享首选项首次安装应用程序时才弹出警告框。
By default at starting the shared preference should be false and when the user installs the app and the alert box should appear, after that the shared preference should change to true.默认情况下,在启动时共享首选项应为 false,当用户安装应用程序并出现警告框时,共享首选项应更改为 true。
When next time user opens the app, by the shared preference(true) it shouldn't show the alert box.下次用户打开应用程序时,根据共享首选项(true),它不应显示警告框。
Only when the user uninstalls and installs the app, the alert box should appear.只有当用户卸载并安装应用程序时,才会出现警告框。
Any idea on how to achieve this?关于如何实现这一目标的任何想法?
Use shared_preferences使用shared_preferences
void main() async {
WidgetsFlutterBinding.ensureInitialized();
final prefs = await SharedPreferences.getInstance();
bool? firstTime = prefs.getBool('first_time');
if (firstTime == null) {
// show alert box
prefs.setBool('first_time', true);
}
runApp(MyApp());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.