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(); } // getInit() async { // await Provider.of(context, listen: false).getSurvey(); // Navigator.pushNamed(context, '/sign-in'); // // await Provider.of(context, listen: false).getTransactions(); // } // void getInit() async { // try { // final surveyProvider = // Provider.of(context, listen: false); // final categoryProvider = // Provider.of(context, listen: false); // await surveyProvider.getSurvey(); // await categoryProvider.getCategory(); // } catch (e) { // print('Error during getInit: $e'); // } // } 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 // void initState() { // super.initState(); // getInit(); // } // void getInit() async { // await Provider.of(context, listen: false).getSurvey(); // Timer(Duration(seconds: 2), () { // Navigator.pushNamed(context, '/sign-in'); // // Navigator.pushNamed(context, '/home'); // }); // } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: backgroundColor1, body: Center( child: Container( width: 130, height: 150, child: FlutterLogo(), // decoration: BoxDecoration( // image: DecorationImage( // image: AssetImage('assets/gps_samara.jpeg'), // ), // ), ), ), ); } }