Skip to content

Commit 09163f5

Browse files
author
Vivek Chib
committed
changes to theme switcher
1 parent cebf01f commit 09163f5

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

lib/main.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ Future<void> main() async {
1717
MultiProvider(
1818
providers: [
1919
ChangeNotifierProvider(create: (context) => ThemeProvider(pref: pref)),
20-
ChangeNotifierProvider(create: (context) => AnimatedBoxesProvider(pref: pref)),
20+
ChangeNotifierProvider(
21+
create: (context) => AnimatedBoxesProvider(pref: pref)),
2122
],
2223
child: const MyApp(),
2324
),

lib/views/home_page.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
7171
});
7272
}
7373

74-
void updateCurve(CurveModel curve) {
75-
if (curve == selectedCurve) return;
74+
void updateCurve(CurveModel? curve) {
75+
if (curve == null || curve == selectedCurve) return;
7676

7777
setState(() {
7878
selectedCurve = curve;
@@ -192,7 +192,7 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
192192
title: "Curve",
193193
value: selectedCurve,
194194
items: CurveModel.list[selectedCategory]!.toList(),
195-
onChanged: (value) => updateCurve(value!),
195+
onChanged: updateCurve,
196196
builder: (context, value, textStyle) {
197197
return Text(value.name.toString(), style: textStyle);
198198
},

lib/views/widgets/animated_theme_switch/painter.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class ThemeSwitchPainter extends CustomPainter {
3333
canvas.translate(center.dx, center.dy);
3434

3535
// rotate canvas with animation value
36-
canvas.rotate(1 - animation.value * pi);
36+
canvas.rotate((1 - animation.value) * pi / 2);
3737

3838
// draw a box with an additional path to clip center circle
3939
canvas.drawPath(
@@ -61,16 +61,16 @@ class ThemeSwitchPainter extends CustomPainter {
6161

6262
// now draw a circle at the center
6363
// and translate it with animation to form a moon shape from center to top-right
64-
final moonRadius = radius - 2;
64+
final moonRadius = radius * .70;
6565

66-
final translateX = size.width / 2 + (animation.value * size.width * .10);
67-
final translateY = size.height / 2 - (animation.value * size.height * .10);
66+
final translateX = size.width / 2 + (animation.value * size.width * .125);
67+
final translateY = size.height / 2 - (animation.value * size.height * .075);
6868

6969
canvas.drawCircle(Offset(translateX, translateY), moonRadius, canvasPaint);
7070
}
7171

7272
@override
73-
bool shouldRepaint(covariant CustomPainter oldDelegate) {
74-
return false;
73+
bool shouldRepaint(covariant ThemeSwitchPainter oldDelegate) {
74+
return oldDelegate.animation.value != animation.value;
7575
}
7676
}

lib/views/widgets/animated_theme_switch/widget.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class AnimatedThemeSwitcher extends StatefulWidget {
1111
}
1212

1313
class _AnimatedThemeSwitcherState extends State<AnimatedThemeSwitcher>
14-
with TickerProviderStateMixin {
14+
with SingleTickerProviderStateMixin {
1515
late AnimationController controller;
1616

1717
late Animation<double> animation;
@@ -21,12 +21,12 @@ class _AnimatedThemeSwitcherState extends State<AnimatedThemeSwitcher>
2121
super.initState();
2222
controller = AnimationController(
2323
vsync: this,
24-
duration: const Duration(milliseconds: 500),
24+
duration: const Duration(milliseconds: 750),
2525
);
2626

2727
animation = CurvedAnimation(
2828
parent: controller,
29-
curve: Curves.easeInOutCubic,
29+
curve: Curves.easeInOutBack,
3030
);
3131
}
3232

0 commit comments

Comments
 (0)