diff --git a/lib/pages/splash_page.dart b/lib/pages/splash_page.dart index ba265a7..46049d4 100644 --- a/lib/pages/splash_page.dart +++ b/lib/pages/splash_page.dart @@ -1,6 +1,5 @@ import 'dart:async'; -// import 'package:commerce_flutter/providers/product_provider.dart'; import 'package:provider/provider.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:siopas/models/user_model.dart'; @@ -18,7 +17,6 @@ class _SplashPageState extends State { @override void initState() { super.initState(); - // getInit(); autoLogin(); } @@ -29,27 +27,34 @@ class _SplashPageState extends State { AuthProvider authProvider = Provider.of(context, listen: false); - UserModel user = authProvider.user; if (token != null) { bool loginSuccess = await authProvider.autoLogin(); if (loginSuccess) { - Navigator.pushNamed(context, '/home'); - print('Berhasil Login 1 (otomatis splash screen)'); + Navigator.pushReplacementNamed(context, '/home'); + print('Berhasil Login (otomatis splash screen)'); } else { - Navigator.pushNamed(context, '/sign-in'); - print('Gagal Login 1 (otomatis splash screen)'); + redirectToLogin(); } } else { - Navigator.pushNamed(context, '/sign-in'); - print('Gagal Login 2 (otomatis splash screen)'); + redirectToLogin(); } } catch (error) { print('Terjadi kesalahan: $error'); - Navigator.pushNamed(context, '/sign-in'); + redirectToLogin(); } } + void redirectToLogin() { + // Tambahkan penundaan 3 detik sebelum pindah ke halaman login + Future.delayed(Duration(seconds: 3), () { + if (mounted) { + Navigator.pushReplacementNamed(context, '/sign-in'); + print('Pindah ke Halaman Login setelah penundaan'); + } + }); + } + @override Widget build(BuildContext context) { return Scaffold( @@ -67,11 +72,9 @@ class _SplashPageState extends State { ), ), ), - SizedBox( - height: - 16), // Jarak antara gambar dan CircularProgressIndicator - CircularProgressIndicator(), // Tambahkan ini - SizedBox(height: 16), // Jarak antara indicator dan teks + SizedBox(height: 16), + CircularProgressIndicator(), + SizedBox(height: 16), Text( 'Memuat...', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),