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'; import 'package:siopas/theme.dart'; import 'package:flutter/material.dart'; import '../providers/auth_provider.dart'; class SplashPage extends StatefulWidget { @override State createState() => _SplashPageState(); } class _SplashPageState extends State { @override void initState() { super.initState(); // getInit(); autoLogin(); } void autoLogin() async { try { SharedPreferences prefs = await SharedPreferences.getInstance(); String? token = prefs.getString('token'); 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)'); } else { Navigator.pushNamed(context, '/sign-in'); print('Gagal Login 1 (otomatis splash screen)'); } } else { Navigator.pushNamed(context, '/sign-in'); print('Gagal Login 2 (otomatis splash screen)'); } } catch (error) { print('Terjadi kesalahan: $error'); Navigator.pushNamed(context, '/sign-in'); } } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: backgroundColor1, body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Container( width: 130, height: 150, decoration: BoxDecoration( image: DecorationImage( image: AssetImage('assets/img/logo_siopas.png'), ), ), ), SizedBox( height: 16), // Jarak antara gambar dan CircularProgressIndicator CircularProgressIndicator(), // Tambahkan ini SizedBox(height: 16), // Jarak antara indicator dan teks Text( 'Memuat...', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold), ), ], ), ), ); } }