简体   繁体   English

首次使用共享首选项安装应用程序时显示警告框 + flutter + dart

[英]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.

相关问题 如何使用 dart/flutter 中的共享首选项保存和获取列表列表 - How to save and get a list of lists using Shared preferences in dart/flutter MediaPlayer - 如何在第一次启动应用程序时显示警报对话框 - MediaPlayer - How to show a alert dialoge when app is launched first time 使用共享首选项时,Android应用程序崩溃 - Android app crashes when using Shared Preferences 启动画面-首次使用共享首选项 - Splashscreen - first Time with shared preferences 关于首次使用Android中的共享首选项打开登录屏幕 - Regarding opening login screen for first time using shared preferences in android 如何在 flutter 端(使用 dart)访问 android 共享首选项(使用 java)? - How to access android Shared preferences(using java) on the flutter end (using dart)? 尝试首次尝试共享首选项 - Trying to experiment shared preferences for the first time 共享的偏好设置-首次检查是否为空 - Shared Preferences - First time check if empty 共享首选项仅在第一次保存 - Shared preferences only saved first time 共享首选项仅适用于首次应用重启。 在重新启动应用程序第二次卡视图标题不保留 - Shared preferences working only for the first app restart. On restarting the app second time card view titles are not retained
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM