Files
kent_logistics_app/lib/screens/splash_screen.dart

75 lines
2.0 KiB
Dart
Raw Normal View History

2025-11-28 10:14:30 +05:30
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../providers/auth_provider.dart';
import 'dashboard_screen.dart';
2025-12-03 11:57:05 +05:30
import 'main_bottom_nav.dart';
2025-11-28 10:14:30 +05:30
import 'welcome_screen.dart';
class SplashScreen extends StatefulWidget {
const SplashScreen({super.key});
2025-12-03 11:57:05 +05:30
2025-11-28 10:14:30 +05:30
@override
State<SplashScreen> createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> {
@override
void initState() {
super.initState();
_init();
}
void _init() async {
2025-12-03 11:57:05 +05:30
await Future.delayed(const Duration(milliseconds: 500));
2025-11-28 10:14:30 +05:30
final auth = Provider.of<AuthProvider>(context, listen: false);
2025-12-03 11:57:05 +05:30
// 🟢 IMPORTANT → WAIT FOR PREFERENCES TO LOAD
await auth.init();
if (!mounted) return;
2025-11-28 10:14:30 +05:30
if (auth.isLoggedIn) {
2025-12-03 11:57:05 +05:30
Navigator.of(context).pushReplacement(
MaterialPageRoute(builder: (_) => const MainBottomNav()),
);
2025-11-28 10:14:30 +05:30
} else {
2025-12-03 11:57:05 +05:30
Navigator.of(context).pushReplacement(
MaterialPageRoute(builder: (_) => const WelcomeScreen()),
);
2025-11-28 10:14:30 +05:30
}
}
@override
Widget build(BuildContext context) {
final size = MediaQuery.of(context).size;
return Scaffold(
body: Center(
child: Column(mainAxisSize: MainAxisSize.min, children: [
Container(
width: size.width * 0.34,
height: size.width * 0.34,
2025-12-03 11:57:05 +05:30
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Theme.of(context).primaryColor.withOpacity(0.14),
),
child: Center(
child: Text(
"K",
style: TextStyle(
fontSize: 48,
fontWeight: FontWeight.bold,
color: Theme.of(context).primaryColor),
),
),
2025-11-28 10:14:30 +05:30
),
const SizedBox(height: 18),
2025-12-03 11:57:05 +05:30
const Text("Kent Logistics",
style: TextStyle(fontSize: 20, fontWeight: FontWeight.w600)),
2025-11-28 10:14:30 +05:30
]),
),
);
}
}