import 'dart:developer'; import 'package:flutter/material.dart'; import '../../config/provider.dart'; import '../../providers/auth_provider.dart'; import '../../providers/chat_v2/chat_socket_stream_provider.dart'; import '../../providers/client_picker_provider.dart'; import '../../providers/language_provider.dart'; import '../../providers/navbar_provider/client_bottom_nav_provider.dart'; import '../../providers/utils_provider.dart'; import '../../services/chat_v2/chat_socket.dart'; import '../../utils/text_style.dart'; import '../../utils/text_widget.dart'; import '../../config/app_constant.dart'; import '../../config/size.dart'; import '../../config/style.dart'; import '../../utils/utils_singleton.dart'; import '../../widgets/custom_botton_widget.dart'; import '../../widgets/home_indicator_widget.dart'; import '../role_pick/pick_a_role_screen.dart'; class Splash extends StatefulWidget { const Splash({Key? key}) : super(key: key); @override State createState() => _SplashState(); } class _SplashState extends State { final hm = SizeConfig.heightMultiplier; final wm = SizeConfig.widthMultiplier; final tm = SizeConfig.textMultiplier; @override void initState() { init(true); super.initState(); } init(bool isInit) async { // int? tokenExpiresIn; if (isInit) { context.read().initPlatformState(); context.read().getIpAddress(); if (context.read().prefs != null) { if (context.read().prefs!.getString("token") != null && context.read().prefs!.getString("token") != "" && context.read().prefs!.getString("token") != "InvalidToken") { // bool isExpired = // context.read().isTokenExpired(tokenExpiresIn!); // if (isExpired) { // context.read().refreshToken(); // } if (await context.read().isTechnician()) { log('User Is Technicien'); // Awaited so goToHomeScreen can check the role the server issued // rather than the local "Role" preference. await context.read().fetchProfile(context); ChatSocket chatSocket = ChatSocket(); await chatSocket.connectSock(); await context .read() .setChatSocketStream(chatSocket); context .read() .goToHomeScreen(context, 'ROLE_TECHNICIAN', true); } else { log('User Is user'); context .read() .setUserConnectionState(true); await context.read().fetchProfile(context); ChatSocket chatSocket = ChatSocket(); await chatSocket.connectSock(); await context .read() .setChatSocketStream(chatSocket); context .read() .goToHomeScreen(context, 'ROLE_CLIENT', true); } } } } else { Navigator.push( context, MaterialPageRoute(builder: (context) => RolePickScreen())); } } @override Widget build(BuildContext context) { final langProvider = Provider.of(context); return Scaffold( backgroundColor: AppStyle.appBackground, body: Center( child: SingleChildScrollView( child: Column( crossAxisAlignment: CrossAxisAlignment.center, children: [ Padding( padding: EdgeInsetsDirectional.only(top: hm * 5, start: wm * 10, end: wm * 20), child: Txt( text: "An assistant to carry out all your maintenance work", style: tS( "Inter", 20, FontWeight.bold, AppStyle.primary ) ), ), SizedBox( height: hm * 60, child: Padding( padding: EdgeInsetsDirectional.only( top: hm * 2, start: wm * 10, end: wm * 10, bottom: hm * 2), child: Image.asset(Consts.starterPhoto)), ), SizedBox( width: wm * 100 / 1.5, child: Txt( text: "Start by selecting your preferred language", textAlign: TextAlign.center, maxLines: 2, style: tS( "Inter", tm * 2.6, FontWeight.w400, AppStyle.primary, ) ), ), Padding( padding: const EdgeInsets.symmetric(horizontal: 50.0), child: Row( mainAxisAlignment: MainAxisAlignment.spaceAround, crossAxisAlignment: CrossAxisAlignment.center, children: [ Expanded( child: Padding( padding: EdgeInsets.only(top: hm * 2, bottom: hm), child: GestureDetector( onTap: () { langProvider.changeLanguage("English"); init(false); }, child: const CustomButtonWidget( height: 40, width: 130, borderRadius: 10, fontSize: 20, fillColor: AppStyle.buttonBlue, borderColor: AppStyle.buttonBlue, textColor: AppStyle.white, text: 'English', fontFamily: 'lato-regular', fontWeight: FontWeight.normal, ), ), ), ), SizedBox(width: 17,), Expanded( child: Padding( padding: EdgeInsets.only(top: hm), child: GestureDetector( onTap: () { langProvider.changeLanguage("Arabic"); init(false); }, child: const CustomButtonWidget( height: 40, width: 130, borderRadius: 10, fontSize: 20, fillColor: Colors.transparent, borderColor: AppStyle.buttonBlue, textColor: AppStyle.buttonBlue, text: 'العربية', fontFamily: 'lato-regular', fontWeight: FontWeight.bold, ), ), ), ), ], ), ), // HomeIndicatorBottomWidget(), ], ), ), ), ); } }