Advertisement
mrblab

lib/pages/splash.dart

Dec 21st, 2023
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 2.56 KB | None | 0 0
  1. import 'dart:async';
  2. import 'package:flutter/material.dart';
  3. import 'package:provider/provider.dart';
  4. import 'package:quiz_app/configs/app_config.dart';
  5. import 'package:quiz_app/pages/home.dart';
  6. import 'package:quiz_app/pages/intro.dart';
  7. import 'package:quiz_app/services/auth_service.dart';
  8. import 'package:quiz_app/utils/next_screen.dart';
  9. import 'package:simple_animations/simple_animations.dart';
  10.  
  11. import '../blocs/ads_bloc.dart';
  12. import '../blocs/settings_bloc.dart';
  13. import '../blocs/user_bloc.dart';
  14. import '../configs/color_config.dart';
  15.  
  16. class SplashPage extends StatefulWidget {
  17.   const SplashPage({Key? key}) : super(key: key);
  18.  
  19.   @override
  20.   State<SplashPage> createState() => _SplashPageState();
  21. }
  22.  
  23. class _SplashPageState extends State<SplashPage> {
  24.  
  25.  
  26.   // Hot fix for null issue when user data get deleted
  27.   _getRequiredData() async {
  28.     await AuthService().checkUserState().then((bool isSignedIn) async {
  29.       if (isSignedIn) {
  30.         await context.read<UserBloc>().getUserData().then((value) async {
  31.           if (context.read<UserBloc>().userData != null) {
  32.             await context.read<SettingsBloc>().getSettingsData().then((value) async => await context.read<AdsBloc>().checkAds()).then((value) async {
  33.               await context.read<SettingsBloc>().getSpecialCategories();
  34.               debugPrint('Data getting done');
  35.               await Future.delayed(const Duration(seconds: 1)).then((_) => NextScreen().nextScreenReplaceAnimation(context, const HomePage()));
  36.             });
  37.           } else {
  38.             await AuthService().userLogOut();
  39.             await Future.delayed(const Duration(seconds: 2)).then((_) => NextScreen().nextScreenReplaceAnimation(context, const IntroPage()));
  40.           }
  41.         });
  42.       } else {
  43.         await Future.delayed(const Duration(seconds: 2)).then((_) => NextScreen().nextScreenReplaceAnimation(context, const IntroPage()));
  44.       }
  45.     });
  46.   }
  47.  
  48.   @override
  49.   void initState() {
  50.     super.initState();
  51.     _getRequiredData();
  52.   }
  53.  
  54.   @override
  55.   Widget build(BuildContext context) {
  56.     return Scaffold(
  57.         backgroundColor: ColorConfig.secondaryBgColor,
  58.         body: MirrorAnimationBuilder<double>(
  59.           curve: Curves.easeInOut,
  60.           tween: Tween(begin: 100.0, end: 180),
  61.           duration: const Duration(milliseconds: 900),
  62.           builder: (context, value, _) {
  63.             return Center(
  64.                 child: Image.asset(
  65.               Config.splashIcon,
  66.               height: value,
  67.               width: value,
  68.             ));
  69.           },
  70.         ));
  71.   }
  72. }
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement