Browse Source

perbaikan splash screen

master
unknown 1 year 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 'dart:async';
// import 'package:commerce_flutter/providers/product_provider.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'package:siopas/models/user_model.dart'; import 'package:siopas/models/user_model.dart';
@ -18,7 +17,6 @@ class _SplashPageState extends State<SplashPage> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
// getInit();
autoLogin(); autoLogin();
} }
@ -29,27 +27,34 @@ class _SplashPageState extends State<SplashPage> {
AuthProvider authProvider = AuthProvider authProvider =
Provider.of<AuthProvider>(context, listen: false); Provider.of<AuthProvider>(context, listen: false);
UserModel user = authProvider.user;
if (token != null) { if (token != null) {
bool loginSuccess = await authProvider.autoLogin(); bool loginSuccess = await authProvider.autoLogin();
if (loginSuccess) { if (loginSuccess) {
Navigator.pushNamed(context, '/home'); Navigator.pushReplacementNamed(context, '/home');
print('Berhasil Login 1 (otomatis splash screen)'); print('Berhasil Login (otomatis splash screen)');
} else { } else {
Navigator.pushNamed(context, '/sign-in'); redirectToLogin();
print('Gagal Login 1 (otomatis splash screen)');
} }
} else { } else {
Navigator.pushNamed(context, '/sign-in'); redirectToLogin();
print('Gagal Login 2 (otomatis splash screen)');
} }
} catch (error) { } catch (error) {
print('Terjadi kesalahan: $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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
@ -67,11 +72,9 @@ class _SplashPageState extends State<SplashPage> {
), ),
), ),
), ),
SizedBox( SizedBox(height: 16),
height: CircularProgressIndicator(),
16), // Jarak antara gambar dan CircularProgressIndicator SizedBox(height: 16),
CircularProgressIndicator(), // Tambahkan ini
SizedBox(height: 16), // Jarak antara indicator dan teks
Text( Text(
'Memuat...', 'Memuat...',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold), style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),

Loading…
Cancel
Save