feat: Added color theme

This commit is contained in:
Deven Joshi
2021-02-16 18:47:19 +05:30
parent 714b562444
commit 01bc4291f5
+35 -5
View File
@@ -39,6 +39,7 @@ class _MyAppState extends State<MyApp> with TickerProviderStateMixin {
bool _animCompleted = false; bool _animCompleted = false;
Animation<double> _animation; Animation<double> _animation;
AnimationController _animationController; AnimationController _animationController;
Animation<Color> _colorAnimation;
Future<InitData> _initConnection() async { Future<InitData> _initConnection() async {
final secureStorage = FlutterSecureStorage(); final secureStorage = FlutterSecureStorage();
@@ -70,11 +71,32 @@ class _MyAppState extends State<MyApp> with TickerProviderStateMixin {
AnimationController(vsync: this, duration: Duration(milliseconds: 300)); AnimationController(vsync: this, duration: Duration(milliseconds: 300));
_animation = Tween(begin: 0.0, end: 1000.0).animate( _animation = Tween(begin: 0.0, end: 1000.0).animate(
CurvedAnimation(parent: _animationController, curve: Curves.easeInOut)); CurvedAnimation(parent: _animationController, curve: Curves.easeInOut));
_colorAnimation =
ColorTween(begin: Color(0xff005FFF), end: Color(0xff005FFF)).animate(
CurvedAnimation(
parent: _animationController, curve: Curves.easeInOut));
_initConnection().then( _initConnection().then(
(initData) { (initData) {
setState(() { setState(() {
_initData = initData; _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(); _animationController.forward();
}, },
); );
@@ -94,17 +116,23 @@ class _MyAppState extends State<MyApp> with TickerProviderStateMixin {
clipBehavior: Clip.none, clipBehavior: Clip.none,
alignment: Alignment.center, alignment: Alignment.center,
children: [ children: [
Container( AnimatedBuilder(
animation: _colorAnimation,
builder: (context, snapshot) {
return Container(
alignment: Alignment.center, alignment: Alignment.center,
constraints: BoxConstraints.expand(), constraints: BoxConstraints.expand(),
color: Color(0xff005FFF), color: _colorAnimation == null
? Color(0xff005FFF)
: _colorAnimation.value,
child: _initData == null child: _initData == null
? Lottie.asset( ? Lottie.asset(
'assets/floating_boat.json', 'assets/floating_boat.json',
alignment: Alignment.center, alignment: Alignment.center,
) )
: Container(), : Container(),
), );
}),
if (_initData != null) if (_initData != null)
AnimatedBuilder( AnimatedBuilder(
animation: _animation, animation: _animation,
@@ -115,12 +143,14 @@ class _MyAppState extends State<MyApp> with TickerProviderStateMixin {
width: 1.0, width: 1.0,
height: 1.0, height: 1.0,
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.white.withOpacity(0.7), color: Colors.white
.withOpacity(1 - _animationController.value),
shape: BoxShape.circle, shape: BoxShape.circle,
), ),
), ),
); );
}), },
),
], ],
), ),
); );