Search
 
SCRIPT & CODE EXAMPLE
 

DART

onetime onboarding flutter


Flutter Onboarding Screen only one time from onboarding to Login to Mainscreen







Future < void > main() async {

  runApp(const MyApp());
}

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

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
      statusBarColor: Colors.transparent, // transparent status bar
      statusBarIconBrightness: Brightness.dark // dark text for status bar
    ));
    //get stored int from sharedpref
    Future < int > alreadyAUser = IsFirstTime().getOnce();

    return MultiProvider(
      providers: AppProviders.providers,
      child: MaterialApp(
        debugShowCheckedModeBanner: false,
        routes: AppRoutes.routes(),
        home: FutureBuilder(
          builder: (ctx, snapshot) {
            // Checking if future is resolved or not
            if (snapshot.connectionState == ConnectionState.done) {
              // If data is present
              if (snapshot.hasData) {
                final data = snapshot.data as int;
                print(data);
                switch (data) {
                  case 0:
                    return OnboardingScreen();

                  case 1:
                    return LoginScreen();

                  case 2:
                    return MainScreen();
                }

                // if we got our data
              }
            }

            // Displaying blank to indicate waiting state
            return Container(
              color: Colors.white,
            );
          },

          // Future that needs to be resolved
          // inorder to display something on the Canvas
          future: alreadyAUser,
        ),
      ),
    );
  }
}

class IsFirstTime {
  Future < int > getOnce() async {
    int ? intValue;
    SharedPreferences prefs = await SharedPreferences.getInstance();
    //Return String

    if (prefs.getInt("initScreen") == null) {
      intValue = 0;
    } else {
      intValue = prefs.getInt("initScreen");
    }

    return intValue!;
  }

  Future once(int num) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    //initScreen
    await prefs.setInt("initScreen", num);

    int initScreen = (prefs.getInt("initScreen")) !;
    print('initScreen ${initScreen}');
    // return initScreen;
  }
}



class OnboardingScreen extends StatefulWidget {
  OnboardingScreen({
    Key ? key
  }): super(key: key);

  @override
  State < OnboardingScreen > createState() => _onboardingScreenState();
}

class _onboardingScreenState extends State < OnboardingScreen > {
  @override
  Widget build(BuildContext context) {
    return Container(
      child: Center(
        child: GestureDetector(
          onTap: () {
            IsFirstTime().once(1);

            //navigate
          },
          child: Text('Login screen something')),
      ));
  }
}
class login extends StatefulWidget {
  login({
    Key ? key
  }): super(key: key);

  @override
  State < login > createState() => _loginState();
}

class _loginState extends State < login > {
  @override
  Widget build(BuildContext context) {
    return Container(
      child: Center(
        child: GestureDetector(
          onTap: () {
            IsFirstTime().once(2);
            //navigate to mainscreen
          },
          child: Text('Login screen something')),
      ));
  }
}
Comment

PREVIOUS NEXT
Code Example
Dart :: flutter color 
Dart :: dart map clear 
Dart :: flutter bottom sheet input button overlay flow by 
Dart :: if else dart example 
Dart :: flutter container with custom shape 
Dart :: flutter crop captured image 
Dart :: global navigator key flutter 
Dart :: Flutter - FlutterLogo Widget 
Dart :: Modal overlay in flutter 
Dart :: pass by reference in dart 
Dart :: rounded button flutter 
Dart :: ~/ vs / dart 
Dart :: tooltip flutter 
Dart :: dart 2d list join 
Dart :: load svg in imageprovider flutter 
Dart :: multi-dimensional list in dart 
Dart :: flutter string add , for 1000 
Dart :: dart break double for loop 
Dart :: automatic keepalive flutter tabs 
Dart :: flutter contaienr 
Swift :: random string swift 
Swift :: set image width and height swiftui 
Swift :: get tabbar height swift 
Swift :: swift collection view cell size 
Swift :: swiftui navigation link with button 
Swift :: convert data to json swift 
Swift :: how to get current shown collectionview cell index in swift 
Swift :: dark mode change immediately swift 
Swift :: convert dictionary to array swift 
Swift :: swift convert base64 string to data 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =