Ad

Flutter & Introduction Slider : How Do We Know That It Is The First Time Our User Open The Open?

- 1 answer

Flutter & Introduction Slider : I want to include introduction slider using this Intro_Slider Plugin. How do we determine when is the first time our user uses the app?

Ad

Answer

You can define a boolean field as isFirstTime and set it to true default value. In initState() of Intro_Slider you can set it to false, that means user visited this page. And you can save it into LocalStorage. After that you can check this value and if isFirstTime is false then you can pass this page.

Add package in pubspec.yaml:

   dependencies:   
      shared_preferences: ^0.5.8

Import it:

   import 'package:shared_preferences/shared_preferences.dart';

Then:

  

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

  void checkIsFirstTime() async {
    final SharedPreferences prefs = await SharedPreferences.getInstance();
    final bool isFirstTime = prefs.getBool('isFirstTime');

    // check is null or true 
    if (isFirstTime == null || isFirstTime) {     
        prefs.setBool('isFirstTime', false);
    }
    else {
        Navigator.push(
            context,
            MaterialPageRoute(builder: (context) => HomePage()),
    }

  }

You can read more.

Ad
source: stackoverflow.com
Ad