Skip to content

Commit f839cc5

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

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
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/widgets/animated_theme_switch/painter.dart

Lines changed: 5 additions & 5 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(animation.value * pi);
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

6666
final translateX = size.width / 2 + (animation.value * size.width * .10);
67-
final translateY = size.height / 2 - (animation.value * size.height * .10);
67+
final translateY = size.height / 2 - (animation.value * size.height * .125);
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
}

0 commit comments

Comments
 (0)