84 lines
2.0 KiB
Dart
84 lines
2.0 KiB
Dart
import 'dart:convert';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_svg/svg.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import '../Login Screen/login_screen.dart';
|
|
import '../main_app_screen/tabbed_layout_component.dart';
|
|
|
|
class SplashScreen extends StatefulWidget {
|
|
const SplashScreen({super.key});
|
|
|
|
@override
|
|
State<SplashScreen> createState() => _SplashScreenState();
|
|
}
|
|
|
|
class _SplashScreenState extends State<SplashScreen> {
|
|
var isLogin = false;
|
|
|
|
Map<String, dynamic> userData = {};
|
|
|
|
|
|
|
|
Future<void> checkifLogin() async {
|
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
bool? isLoggedIn = prefs.getBool('isLoggedIn');
|
|
var userdatastr = prefs.getString('userData');
|
|
|
|
if (kDebugMode) {
|
|
print('userData....$userdatastr');
|
|
}
|
|
if (isLoggedIn != null && isLoggedIn) {
|
|
setState(() {
|
|
isLogin = true;
|
|
});
|
|
}
|
|
|
|
if (userdatastr != null) {
|
|
try{
|
|
userData = json.decode(userdatastr);
|
|
if (kDebugMode) {
|
|
print(userData['token']);
|
|
}
|
|
}catch(e){
|
|
if (kDebugMode) {
|
|
print("error is ..................$e");
|
|
}
|
|
}
|
|
|
|
} else {
|
|
setState(() {
|
|
isLogin = false;
|
|
});
|
|
}
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
checkifLogin().then((value) async => {
|
|
Future.delayed(const Duration(seconds: 2), () {
|
|
Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => isLogin
|
|
? TabbedLayoutComponent(): const LoginScreen()
|
|
),);
|
|
})
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
body: SingleChildScrollView(
|
|
child: Container(
|
|
width: MediaQuery.of(context).size.width,
|
|
height: MediaQuery.of(context).size.height,
|
|
child: Center(
|
|
child: SvgPicture.asset(
|
|
'assets/images/cloudnsuresp.svg',
|
|
width: 100,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
} |