'How to check if it's the first time a user launches an app using is_first_run library?

I tried using the is_first_run package to check if it's the first time my app has been launched. It actually worked as intended the first time I ever tested it. It took the user to the Welcome page on first launch, and then subsequent launches went to the Sign up or Log in page. But any efforts to recreate it again to make sure it's working have failed, and instead it takes me straight to Sign up or Log in, even after uninstalling the app from my device, running flutter clean, deleting all cache and storage for the app, and testing it on a completely different device. Any reason why it's not working anymore?

Here is the entire code for my main file:

import 'package:screens/welcomepages/signup_or_login.dart';
import 'package:screens/welcomepages/welcome.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:config/theme.dart';
import 'package:is_first_run/is_first_run.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
      statusBarColor: Colors.transparent,
      statusBarBrightness: Brightness.dark));
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    var ifr = _checkFirstRun();
    if (ifr == true) {
      return MaterialApp(
        theme: theme(),
        debugShowCheckedModeBanner: false,
        home: const Welcome(),
      );
    }
    return MaterialApp(
      theme: theme(),
      debugShowCheckedModeBanner: false,
      home: const SignUpOrLogIn(),
    );
  }
}

Future<bool> _checkFirstRun() async {
  return await IsFirstRun.isFirstRun();
}

Any alternative solutions also welcome.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source