From faeca1adbd496368b028832f35eb350c92a40936 Mon Sep 17 00:00:00 2001 From: Vadim <44135514+vodemn@users.noreply.github.com> Date: Tue, 30 Apr 2024 21:57:02 +0200 Subject: [PATCH] animated timeline --- lib/screens/timer/flow_timer.dart | 4 ++- lib/screens/timer/screen_timer.dart | 43 +++++++++++++++-------------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/lib/screens/timer/flow_timer.dart b/lib/screens/timer/flow_timer.dart index 7b3367f..622618a 100644 --- a/lib/screens/timer/flow_timer.dart +++ b/lib/screens/timer/flow_timer.dart @@ -24,7 +24,9 @@ class TimerFlow extends StatelessWidget { MeteringInteractorProvider.of(context), 124, ), - child: const TimerScreen(), + child: const TimerScreen( + duration: const Duration(seconds: 124), + ), ), ); } diff --git a/lib/screens/timer/screen_timer.dart b/lib/screens/timer/screen_timer.dart index 39ede74..650f4c8 100644 --- a/lib/screens/timer/screen_timer.dart +++ b/lib/screens/timer/screen_timer.dart @@ -10,7 +10,9 @@ import 'package:lightmeter/screens/timer/state_timer.dart'; import 'package:material_color_utilities/material_color_utilities.dart'; class TimerScreen extends StatefulWidget { - const TimerScreen({super.key}); + final Duration duration; + + const TimerScreen({required this.duration, super.key}); @override State createState() => _TimerScreenState(); @@ -26,11 +28,11 @@ class _TimerScreenState extends State with TickerProviderStateMixin void initState() { super.initState(); - timelineController = AnimationController(vsync: this, duration: Dimens.durationS); - timelineAnimation = Tween(begin: 0.0, end: 1.0).animate(timelineController); + timelineController = AnimationController(vsync: this, duration: widget.duration); + timelineAnimation = Tween(begin: 1, end: 0).animate(timelineController); startStopIconController = AnimationController(vsync: this, duration: Dimens.durationS); - startStopIconAnimation = Tween(begin: 0.0, end: 1.0).animate(startStopIconController); + startStopIconAnimation = Tween(begin: 0, end: 1).animate(startStopIconController); } @override @@ -75,22 +77,21 @@ class _TimerScreenState extends State with TickerProviderStateMixin mainAxisAlignment: MainAxisAlignment.center, children: [ const Spacer(), - // SizedBox.fromSize( - // size: Size.square(MediaQuery.sizeOf(context).width - Dimens.paddingL * 4), - // child: BlocBuilder( - // builder: (context, state) { - // return _Timer( - // timeLeft: state.timeLeft, - // duration: state.duration, - // ); - // }, - // ), - // ), - BlocBuilder( - buildWhen: (previous, current) => previous.timeLeft != current.timeLeft, - builder: (_, state) => _Timer( - timeLeft: state.timeLeft, - duration: state.duration, + SizedBox.fromSize( + size: Size.square(MediaQuery.sizeOf(context).width - Dimens.paddingL * 4), + child: ValueListenableBuilder( + valueListenable: timelineAnimation, + builder: (_, value, child) => _TimerTimeline( + progress: value, + child: child!, + ), + child: BlocBuilder( + buildWhen: (previous, current) => previous.timeLeft != current.timeLeft, + builder: (_, state) => _Timer( + timeLeft: state.timeLeft, + duration: state.duration, + ), + ), ), ), const Spacer(), @@ -120,8 +121,10 @@ class _TimerScreenState extends State with TickerProviderStateMixin switch (state) { case TimerResumedState(): startStopIconController.forward(); + timelineController.forward(); case TimerStoppedState(): startStopIconController.reverse(); + timelineController.stop(); } } }