【问题标题】:show an alert box when the app is installed for the first time using shared preferences + flutter + dart使用共享首选项 + flutter + dart 首次安装应用程序时显示警告框
【发布时间】:2023-01-24 14:00:18
【问题描述】:

我正在开发一个安卓应用程序,

我希望仅当用户使用共享首选项首次安装应用程序时才弹出警告框。

默认情况下,在启动时共享首选项应为 false,当用户安装应用程序并出现警告框时,共享首选项应更改为 true。

下次用户打开应用程序时,根据共享首选项(true),它不应显示警告框。

只有当用户卸载并安装应用程序时,才会出现警告框。

关于如何实现这一目标的任何想法?

【问题讨论】:

    标签: android flutter dart sharedpreferences splash-screen


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-23
      • 1970-01-01
      • 2019-10-01
      • 2019-02-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多