From 01bc4291f5e3400b11728481cfadd7ac537e3f92 Mon Sep 17 00:00:00 2001 From: Deven Joshi Date: Tue, 16 Feb 2021 18:47:19 +0530 Subject: [PATCH] feat: Added color theme --- stream_chat_v1/lib/main.dart | 78 +++++++++++++++++++++++++----------- 1 file changed, 54 insertions(+), 24 deletions(-) diff --git a/stream_chat_v1/lib/main.dart b/stream_chat_v1/lib/main.dart index 2acd048..5c7dfa3 100644 --- a/stream_chat_v1/lib/main.dart +++ b/stream_chat_v1/lib/main.dart @@ -39,6 +39,7 @@ class _MyAppState extends State with TickerProviderStateMixin { bool _animCompleted = false; Animation _animation; AnimationController _animationController; + Animation _colorAnimation; Future _initConnection() async { final secureStorage = FlutterSecureStorage(); @@ -70,11 +71,32 @@ class _MyAppState extends State with TickerProviderStateMixin { AnimationController(vsync: this, duration: Duration(milliseconds: 300)); _animation = Tween(begin: 0.0, end: 1000.0).animate( CurvedAnimation(parent: _animationController, curve: Curves.easeInOut)); + _colorAnimation = + ColorTween(begin: Color(0xff005FFF), end: Color(0xff005FFF)).animate( + CurvedAnimation( + parent: _animationController, curve: Curves.easeInOut)); _initConnection().then( (initData) { setState(() { _initData = initData; }); + var theme = _initData.preferences.getInt( + 'theme', + defaultValue: 0, + ); + + final isDark = Theme.of(context).brightness == Brightness.dark; + final colorTheme = theme.getValue() == 0 + ? (isDark ? ColorTheme.dark() : ColorTheme.light()) + : (theme.getValue() == 1 ? ColorTheme.light() : ColorTheme.dark()); + + _colorAnimation = ColorTween( + begin: Color(0xff005FFF), + end: colorTheme.white == ColorTheme.light().white + ? Colors.white + : Colors.black) + .animate(CurvedAnimation( + parent: _animationController, curve: Curves.easeInOut)); _animationController.forward(); }, ); @@ -94,33 +116,41 @@ class _MyAppState extends State with TickerProviderStateMixin { 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(), - ), + AnimatedBuilder( + animation: _colorAnimation, + builder: (context, snapshot) { + return Container( + alignment: Alignment.center, + constraints: BoxConstraints.expand(), + color: _colorAnimation == null + ? Color(0xff005FFF) + : _colorAnimation.value, + 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, - ), + 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(1 - _animationController.value), + shape: BoxShape.circle, ), - ); - }), + ), + ); + }, + ), ], ), );