Untitled
unknown
dart
2 years ago
1.2 kB
16
Indexable
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
);
}
}Editor is loading...
Leave a Comment