import 'package:flutter/material.dart'; import 'package:after_layout/after_layout.dart'; import 'package:shared_preferences/shared_preferences.dart'; // import 'lobby_screen.dart'; import 'setup_screen.dart'; import 'home_screen.dart'; import 'loading.dart'; /* * in flutter everything is a widget */ void main() { // main function runApp(const MainApp()); // control starts here } class MainApp extends StatelessWidget { // statelessWidget means a class which will not have an persistent state const MainApp({super.key}); @override Widget build(BuildContext context) { // Every Widget has a build method return MaterialApp( title:'HapticLink', debugShowCheckedModeBanner: false, theme:ThemeData.dark(), // home: SetupScreen(), // home: Loading(), home: const Splash(), // Splash Screen ); } } class Splash extends StatefulWidget { const Splash({super.key}); @override State createState(){ return SplashState(); } } class SplashState extends State with AfterLayoutMixin{ void checkFirstScreen() async{ SharedPreferences prefs = await SharedPreferences.getInstance(); // this is the local storage of any device // if prefs:"setup_done" not set if(prefs.getBool('setup_done')==null){ // if we are using the app for the first time // go to Setup Screen Navigator.pushReplacement( context, MaterialPageRoute( builder: (context)=>SetupScreen() // go to SetupScreen ) ); } else{ // otherwise go to Home Screen directly Navigator.pushReplacement( context, MaterialPageRoute( builder: (context)=>HomeScreen() // go to HomeScreen ) ); } } @override void afterFirstLayout(BuildContext context){ // because of AfterLayoutMixin this method is called automatically after the build method checkFirstScreen(); } @override Widget build(BuildContext context){ return const Loading(); // by default show the loading Widget(Screen) } }