From 714b5624442e159f286b84c263720d17d47c91ad Mon Sep 17 00:00:00 2001 From: Deven Joshi Date: Tue, 16 Feb 2021 17:44:49 +0530 Subject: [PATCH] feat: Added splash animation --- stream_chat_v1/lib/main.dart | 57 +++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 8 deletions(-) diff --git a/stream_chat_v1/lib/main.dart b/stream_chat_v1/lib/main.dart index e99297e..2acd048 100644 --- a/stream_chat_v1/lib/main.dart +++ b/stream_chat_v1/lib/main.dart @@ -34,8 +34,11 @@ class MyApp extends StatefulWidget { _MyAppState createState() => _MyAppState(); } -class _MyAppState extends State { +class _MyAppState extends State with TickerProviderStateMixin { InitData _initData; + bool _animCompleted = false; + Animation _animation; + AnimationController _animationController; Future _initConnection() async { final secureStorage = FlutterSecureStorage(); @@ -63,31 +66,69 @@ class _MyAppState extends State { @override void initState() { + _animationController = + AnimationController(vsync: this, duration: Duration(milliseconds: 300)); + _animation = Tween(begin: 0.0, end: 1000.0).animate( + CurvedAnimation(parent: _animationController, curve: Curves.easeInOut)); _initConnection().then( (initData) { setState(() { _initData = initData; }); + _animationController.forward(); }, ); + _animationController.addStatusListener((status) { + if (status == AnimationStatus.completed) { + setState(() { + _animCompleted = true; + }); + } + }); super.initState(); } Widget _buildAnimation() { - return Container( - alignment: Alignment.center, - constraints: BoxConstraints.expand(), - color: Color(0xff005FFF), - child: Lottie.asset( - 'assets/floating_boat.json', + return MaterialApp( + home: Stack( + clipBehavior: Clip.none, alignment: Alignment.center, + children: [ + Container( + alignment: Alignment.center, + constraints: BoxConstraints.expand(), + color: Color(0xff005FFF), + child: _initData == null + ? Lottie.asset( + 'assets/floating_boat.json', + alignment: Alignment.center, + ) + : Container(), + ), + if (_initData != null) + AnimatedBuilder( + animation: _animation, + builder: (context, snapshot) { + return Transform.scale( + scale: _animation.value, + child: Container( + width: 1.0, + height: 1.0, + decoration: BoxDecoration( + color: Colors.white.withOpacity(0.7), + shape: BoxShape.circle, + ), + ), + ); + }), + ], ), ); } @override Widget build(BuildContext context) { - if (_initData == null) { + if (_initData == null || !_animCompleted) { return _buildAnimation(); }