|
| 1 | +import 'dart:async'; |
| 2 | + |
| 3 | +import 'package:flutter/material.dart'; |
| 4 | +import 'package:lottie/lottie.dart'; |
| 5 | +import 'package:omdb/core/assets/app_assets.dart'; |
| 6 | +import 'package:omdb/core/routes/routes.dart'; |
| 7 | + |
| 8 | +class SplashScreen extends StatefulWidget { |
| 9 | + const SplashScreen({super.key}); |
| 10 | + |
| 11 | + @override |
| 12 | + State<SplashScreen> createState() => _SplashScreenState(); |
| 13 | +} |
| 14 | + |
| 15 | +class _SplashScreenState extends State<SplashScreen> |
| 16 | + with TickerProviderStateMixin { |
| 17 | + late AnimationController animationController; |
| 18 | + late AnimationController fadeController; |
| 19 | + late Animation<double> tweenAnimation; |
| 20 | + late Animation<double> fadeAnimation; |
| 21 | + bool startAlignmentAnimation = false; |
| 22 | + |
| 23 | + @override |
| 24 | + void initState() { |
| 25 | + animationController = AnimationController( |
| 26 | + vsync: this, |
| 27 | + duration: const Duration(seconds: 1), |
| 28 | + ); |
| 29 | + fadeController = AnimationController( |
| 30 | + vsync: this, |
| 31 | + duration: const Duration(milliseconds: 500), |
| 32 | + ); |
| 33 | + tweenAnimation = Tween<double>(begin: 0, end: 38).animate( |
| 34 | + CurvedAnimation(parent: animationController, curve: Curves.bounceOut)) |
| 35 | + ..addListener(() { |
| 36 | + if (animationController.isCompleted) { |
| 37 | + Timer(const Duration(seconds: 1), () { |
| 38 | + fadeController.forward(); |
| 39 | + }); |
| 40 | + } |
| 41 | + setState(() {}); |
| 42 | + }); |
| 43 | + fadeAnimation = Tween<double>(begin: 1, end: 0) |
| 44 | + .animate(CurvedAnimation(parent: fadeController, curve: Curves.easeIn)) |
| 45 | + ..addListener(() { |
| 46 | + if (fadeController.isCompleted) { |
| 47 | + Navigator.pushReplacementNamed(context, AppRoutes.home); |
| 48 | + } |
| 49 | + setState(() {}); |
| 50 | + }); |
| 51 | + animationController.forward(); |
| 52 | + Timer(const Duration(milliseconds: 500), () { |
| 53 | + startAlignmentAnimation = true; |
| 54 | + setState(() {}); |
| 55 | + }); |
| 56 | + super.initState(); |
| 57 | + } |
| 58 | + |
| 59 | + @override |
| 60 | + Widget build(BuildContext context) { |
| 61 | + return Scaffold( |
| 62 | + body: Opacity( |
| 63 | + opacity: fadeAnimation.value, |
| 64 | + child: Center( |
| 65 | + child: Column( |
| 66 | + mainAxisAlignment: MainAxisAlignment.center, |
| 67 | + crossAxisAlignment: CrossAxisAlignment.center, |
| 68 | + children: [ |
| 69 | + Lottie.asset( |
| 70 | + AppAssets.splashAnimationLottie, |
| 71 | + ), |
| 72 | + Row( |
| 73 | + children: [ |
| 74 | + Expanded( |
| 75 | + child: Align( |
| 76 | + alignment: Alignment.centerRight, |
| 77 | + child: Text( |
| 78 | + "OMDB ", |
| 79 | + style: Theme.of(context).textTheme.bodyLarge?.copyWith( |
| 80 | + fontWeight: FontWeight.w700, |
| 81 | + fontSize: tweenAnimation.value, |
| 82 | + color: Colors.yellow[700], |
| 83 | + ), |
| 84 | + ), |
| 85 | + ), |
| 86 | + ), |
| 87 | + Expanded( |
| 88 | + child: AnimatedAlign( |
| 89 | + alignment: !startAlignmentAnimation |
| 90 | + ? Alignment.centerRight |
| 91 | + : Alignment.centerLeft, |
| 92 | + duration: const Duration(milliseconds: 500), |
| 93 | + curve: Curves.easeInOutExpo, |
| 94 | + child: Text( |
| 95 | + "Movies", |
| 96 | + style: Theme.of(context).textTheme.bodyLarge?.copyWith( |
| 97 | + fontWeight: FontWeight.w700, |
| 98 | + fontSize: 38, |
| 99 | + color: Colors.grey[700], |
| 100 | + ), |
| 101 | + ), |
| 102 | + ), |
| 103 | + ), |
| 104 | + ], |
| 105 | + ) |
| 106 | + ], |
| 107 | + ), |
| 108 | + ), |
| 109 | + ), |
| 110 | + ); |
| 111 | + } |
| 112 | +} |
0 commit comments