rd-android-app/lib/screens/splash_screen.dart
2024-10-16 19:04:06 +05:30

114 lines
3.4 KiB
Dart

import 'dart:async';
import 'package:cheminova/screens/authentication/login_screen.dart';
import 'package:cheminova/screens/home_screen.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:shared_preferences/shared_preferences.dart';
class SplashScreen extends StatefulWidget {
const SplashScreen({super.key});
@override
State<SplashScreen> createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> {
@override
void initState() {
Timer(const Duration(seconds: 3), () {
checkLogin();
});
super.initState();
}
checkLogin() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
String? token = prefs.getString('token');
if (token != null) {
Get.offAll(() => const HomeScreen());
} else {
Get.offAll(() => const LoginScreen());
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
margin: EdgeInsets.fromLTRB(
Get.width * 0.07, 0, Get.width * 0.07, Get.height * 0.01),
child: Container(
decoration: const BoxDecoration(
image: DecorationImage(
fit: BoxFit.fill,
image: AssetImage(
'assets/images/px_cheminova_svg.png',
),
),
),
child: SizedBox(
width: Get.width * 0.8,
height: Get.height * 0.05,
),
),
),
Container(
margin: EdgeInsets.only(bottom: Get.height * 0.1),
child: Text(
'HELPING YOU GROW',
style: GoogleFonts.getFont(
'Roboto',
fontWeight: FontWeight.w500,
fontSize: Get.textScaleFactor * 20,
height: 1.3,
color: const Color(0xFF000000),
),
),
),
Container(
margin: EdgeInsets.only(bottom: Get.height * 0.15),
child: Container(
decoration: const BoxDecoration(
image: DecorationImage(
fit: BoxFit.cover,
image: AssetImage(
'assets/images/plant_png_barter_new_sales_ims_barter_trade_exchange_network_33.png',
),
),
),
child: SizedBox(
width: Get.width * 0.8,
height: Get.height * 0.4,
),
),
),
Text(
'Powered By',
style: GoogleFonts.getFont(
'Roboto',
fontWeight: FontWeight.w500,
fontSize: Get.textScaleFactor * 12,
color: const Color(0xFF000000),
),
),
SizedBox(height: Get.height * 0.005), // Reduced spacing
Text(
'codeology.solutions',
style: GoogleFonts.getFont(
'Roboto',
fontWeight: FontWeight.w500,
fontSize: Get.textScaleFactor * 14,
color: const Color(0xFF000000),
),
),
],
),
);
}
}