Sonnat Project
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.
 
 

83 lines
2.8 KiB

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:sonnat/core/extensions/context_extension.dart';
import 'package:sonnat/core/extensions/string_extension.dart';
import 'package:sonnat/core/select_language/cubit/select_language_cubit.dart';
import 'package:sonnat/core/select_language/screen/select_language_screen.dart';
import 'package:sonnat/core/utils/app_constants.dart';
import 'package:sonnat/core/utils/base_cubit_type.dart';
import 'package:sonnat/features/main/main_screen.dart';
import 'package:sonnat/features/splash/cubit/splash_cubit.dart';
class SplashScreen extends StatefulWidget {
const SplashScreen({super.key});
@override
State<SplashScreen> createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> {
late final SplashCubit _cubit;
@override
void initState() {
_cubit = BlocProvider.of<SplashCubit>(context);
Future.delayed(const Duration(milliseconds: 2500), _cubit.checkLanguageSet);
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xff26237A),
body: BlocBuilder<SplashCubit, BaseCubitType<SplashCubitState>>(
builder: (context, state) {
switch (state.eventName!) {
case SplashCubitState.empty:
break;
case SplashCubitState.set:
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return const MainScreen();
},
),
);
});
break;
case SplashCubitState.notSet:
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return BlocProvider(
create: (context) => SelectLanguageCubit(),
child: const SelectLanguageScreen(),
);
},
),
);
});
break;
}
return Center(
child: Container(
margin: EdgeInsets.only(
left: context.width * 86 / AppConstants.instance.appWidth,
right: context.width * 86 / AppConstants.instance.appWidth,
),
child: Image.asset(
'ic_main_header'.pngPath,
width: context.width * 200 / AppConstants.instance.appWidth,
height: context.height * 200 / AppConstants.instance.appHeight,
),
),
);
},
),
);
}
}