From 90f71d37d4c18a5954b06982ce0790842d5522f0 Mon Sep 17 00:00:00 2001 From: Matheus Massula Date: Sun, 19 Apr 2020 19:08:20 -0300 Subject: [PATCH] bug fix and remove comments --- lib/main.dart | 58 ++++++++++++++++++++------------------------------- 1 file changed, 23 insertions(+), 35 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index e15775a..723fef0 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -21,8 +21,6 @@ class MyApp extends StatefulWidget { class MyAppState extends State with TickerProviderStateMixin { AnimationController controller; - // bool isPlaying = false; - String get timerString { Duration duration = controller.duration * controller.value; return '${duration.inMinutes}:${(duration.inSeconds % 60).toString().padLeft(2, '0')}'; @@ -35,14 +33,6 @@ class MyAppState extends State with TickerProviderStateMixin { vsync: this, duration: Duration(seconds: 10), ); - - // ..addStatusListener((status) { - // if (controller.status == AnimationStatus.dismissed) { - // setState(() => isPlaying = false); - // } - - // print(status); - // }) } @override @@ -67,10 +57,11 @@ class MyAppState extends State with TickerProviderStateMixin { builder: (BuildContext context, Widget child) { return CustomPaint( painter: TimerPainter( - animation: controller, - backgroundColor: Colors.white, - color: themeData.indicatorColor, - )); + animation: controller, + backgroundColor: Colors.white, + color: themeData.indicatorColor, + ) + ); }, ), ), @@ -85,13 +76,14 @@ class MyAppState extends State with TickerProviderStateMixin { style: themeData.textTheme.subhead, ), AnimatedBuilder( - animation: controller, - builder: (BuildContext context, Widget child) { - return Text( - timerString, - style: themeData.textTheme.display4, - ); - }), + animation: controller, + builder: (BuildContext context, Widget child) { + return Text( + timerString, + style: themeData.textTheme.display4, + ); + } + ), ], ), ), @@ -110,24 +102,20 @@ class MyAppState extends State with TickerProviderStateMixin { animation: controller, builder: (BuildContext context, Widget child) { return Icon(controller.isAnimating - ? Icons.pause - : Icons.play_arrow); - - // Icon(isPlaying - // ? Icons.pause - // : Icons.play_arrow); + ? Icons.pause + : Icons.play_arrow + ); }, ), onPressed: () { - // setState(() => isPlaying = !isPlaying); - if (controller.isAnimating) { - controller.stop(canceled: true); + setState(() { + controller.stop(canceled: true); + }); } else { controller.reverse( - from: controller.value == 0.0 - ? 1.0 - : controller.value); + from: controller.value == 0.0 ? 1.0 : controller.value + ); } }, ) @@ -168,7 +156,7 @@ class TimerPainter extends CustomPainter { @override bool shouldRepaint(TimerPainter old) { return animation.value != old.animation.value || - color != old.color || - backgroundColor != old.backgroundColor; + color != old.color || + backgroundColor != old.backgroundColor; } }