且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Flutter中检查首次启动应用程序

更新时间:2023-01-25 23:21:53

下面是没有任何错误且说明清楚的代码

Here are code of without any error and clarifying well

class _SplashScreenState extends State<SplashScreen> {

  Future<bool> isFirstTime() async {
     var isFirstTime = SharedPref.pref.getBool('first_time');
     if (isFirstTime != null && !isFirstTime) {
       SharedPref.pref.setBool('first_time', false);
       return false;
     } else {
       SharedPref.pref.setBool('first_time', false);
       return true;
     }
  }

  @override
  void initState() {
    super.initState();

    Timer(Duration(seconds: 3), () {
    isFirstTime().then((isFirstTime) {
      isFirstTime ? print("First time") : print("Not first time");
     });
    }
   );
  }

}