Browse Source

perbaikan splash screen

master
unknown 12 months ago
parent
commit
de078a6bd4
  1. 33
      lib/pages/splash_page.dart

33
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<SplashPage> {
@override
void initState() {
super.initState();
// getInit();
autoLogin();
}
@ -29,27 +27,34 @@ class _SplashPageState extends State<SplashPage> {
AuthProvider authProvider =
Provider.of<AuthProvider>(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<SplashPage> {
),
),
),
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),

Loading…
Cancel
Save