简体   繁体   中英

show an alert box when the app is installed for the first time using shared preferences + flutter + dart

im developing an android app,

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.

When next time user opens the app, by the shared preference(true) it shouldn't show the alert box.

Only when the user uninstalls and installs the app, the alert box should appear.

Any idea on how to achieve this?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM