feat: Added color theme

This commit is contained in:
Deven Joshi
2021-02-16 18:47:19 +05:30
parent 714b562444
commit 01bc4291f5
+54 -24
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,33 +116,41 @@ class _MyAppState extends State<MyApp> with TickerProviderStateMixin {
clipBehavior: Clip.none, clipBehavior: Clip.none,
alignment: Alignment.center, alignment: Alignment.center,
children: [ children: [
Container( AnimatedBuilder(
alignment: Alignment.center, animation: _colorAnimation,
constraints: BoxConstraints.expand(), builder: (context, snapshot) {
color: Color(0xff005FFF), return Container(
child: _initData == null alignment: Alignment.center,
? Lottie.asset( constraints: BoxConstraints.expand(),
'assets/floating_boat.json', color: _colorAnimation == null
alignment: Alignment.center, ? Color(0xff005FFF)
) : _colorAnimation.value,
: Container(), child: _initData == null
), ? Lottie.asset(
'assets/floating_boat.json',
alignment: Alignment.center,
)
: Container(),
);
}),
if (_initData != null) if (_initData != null)
AnimatedBuilder( AnimatedBuilder(
animation: _animation, animation: _animation,
builder: (context, snapshot) { builder: (context, snapshot) {
return Transform.scale( return Transform.scale(
scale: _animation.value, scale: _animation.value,
child: Container( child: Container(
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
shape: BoxShape.circle, .withOpacity(1 - _animationController.value),
), shape: BoxShape.circle,
), ),
); ),
}), );
},
),
], ],
), ),
); );