Siopas Inventory PETI for ISTW Mobile
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

105 lines
2.9 KiB

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<SplashPage> createState() => _SplashPageState();
}
class _SplashPageState extends State<SplashPage> {
@override
void initState() {
super.initState();
// getInit();
autoLogin();
}
// getInit() async {
// await Provider.of<SurveyProvider>(context, listen: false).getSurvey();
// Navigator.pushNamed(context, '/sign-in');
// // await Provider.of<GetTransactionProvider>(context, listen: false).getTransactions();
// }
// void getInit() async {
// try {
// final surveyProvider =
// Provider.of<SurveyProvider>(context, listen: false);
// final categoryProvider =
// Provider.of<CategoryProvider>(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<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)');
} 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<SurveyProvider>(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,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/logo_login.png'),
),
),
),
),
);
}
}