Untitled

mail@pastecode.io avatar
unknown
dart
a month ago
1.2 kB
12
Indexable
Never
void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  // Other initialization if needed
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      home: SplashScreen(),
    );
  }
}

class SplashScreen extends StatefulWidget {
  @override
  _SplashScreenState createState() => _SplashScreenState();
}

class _SplashScreenState extends State<SplashScreen> {

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

  void checkAutoLogin() async {
    bool isLoggedIn = await checkAutoLogin(); // Your implementation
    if (isLoggedIn) {
      Navigator.of(context).pushReplacement(MaterialPageRoute(
        builder: (context) => HomeScreen(), // Navigate to home screen
      ));
    } else {
      Navigator.of(context).pushReplacement(MaterialPageRoute(
        builder: (context) => LoginScreen(), // Navigate to login screen
      ));
    }
  }

  @override
  Widget build(BuildContext context) {
    // Your SplashScreen UI
    return Scaffold(
      body: Center(child: CircularProgressIndicator()), // Or any loading indicator
    );
  }
}
Leave a Comment