83 lines
2.2 KiB
Dart
83 lines
2.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:firebase_auth/firebase_auth.dart';
|
|
|
|
class SplashScreen extends StatefulWidget {
|
|
const SplashScreen({super.key});
|
|
|
|
@override
|
|
State<SplashScreen> createState() => _SplashScreenState();
|
|
}
|
|
|
|
class _SplashScreenState extends State<SplashScreen> {
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_checkAuthStatus();
|
|
}
|
|
|
|
Future<void> _checkAuthStatus() async {
|
|
await Future.delayed(const Duration(seconds: 2));
|
|
final user = FirebaseAuth.instance.currentUser;
|
|
|
|
try {
|
|
if (user != null) {
|
|
// Paksa refresh untuk validasi user masih ada di server
|
|
await user.reload();
|
|
final refreshedUser = FirebaseAuth.instance.currentUser;
|
|
|
|
if (refreshedUser == null) {
|
|
// User sudah dihapus dari server
|
|
Navigator.pushReplacementNamed(context, '/login');
|
|
} else {
|
|
Navigator.pushReplacementNamed(context, '/home');
|
|
}
|
|
} else {
|
|
Navigator.pushReplacementNamed(context, '/login');
|
|
}
|
|
} catch (e) {
|
|
// Jika reload gagal (misalnya user sudah tidak ada)
|
|
await FirebaseAuth.instance.signOut();
|
|
Navigator.pushReplacementNamed(context, '/login');
|
|
}
|
|
}
|
|
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
body: Container(
|
|
decoration: const BoxDecoration(
|
|
gradient: LinearGradient(
|
|
colors: [
|
|
const Color.fromARGB(255, 107, 139, 255),
|
|
Color.fromARGB(255, 139, 164, 255)
|
|
],
|
|
begin: Alignment.topLeft,
|
|
end: Alignment.bottomRight,
|
|
),
|
|
),
|
|
width: double.infinity,
|
|
child: const Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Icon(Icons.water_drop_rounded, size: 100, color: Colors.white),
|
|
SizedBox(height: 24),
|
|
Text(
|
|
'Monitoring Debit Air',
|
|
style: TextStyle(
|
|
fontSize: 26,
|
|
color: Colors.white,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
SizedBox(height: 16),
|
|
CircularProgressIndicator(
|
|
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|