animated timeline

This commit is contained in:
Vadim 2024-04-30 21:57:02 +02:00
parent c532801358
commit faeca1adbd
2 changed files with 26 additions and 21 deletions

View file

@ -24,7 +24,9 @@ class TimerFlow extends StatelessWidget {
MeteringInteractorProvider.of(context),
124,
),
child: const TimerScreen(),
child: const TimerScreen(
duration: const Duration(seconds: 124),
),
),
);
}

View file

@ -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<TimerScreen> createState() => _TimerScreenState();
@ -26,11 +28,11 @@ class _TimerScreenState extends State<TimerScreen> with TickerProviderStateMixin
void initState() {
super.initState();
timelineController = AnimationController(vsync: this, duration: Dimens.durationS);
timelineAnimation = Tween<double>(begin: 0.0, end: 1.0).animate(timelineController);
timelineController = AnimationController(vsync: this, duration: widget.duration);
timelineAnimation = Tween<double>(begin: 1, end: 0).animate(timelineController);
startStopIconController = AnimationController(vsync: this, duration: Dimens.durationS);
startStopIconAnimation = Tween<double>(begin: 0.0, end: 1.0).animate(startStopIconController);
startStopIconAnimation = Tween<double>(begin: 0, end: 1).animate(startStopIconController);
}
@override
@ -75,24 +77,23 @@ class _TimerScreenState extends State<TimerScreen> with TickerProviderStateMixin
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Spacer(),
// SizedBox.fromSize(
// size: Size.square(MediaQuery.sizeOf(context).width - Dimens.paddingL * 4),
// child: BlocBuilder<TimerBloc, TimerState>(
// builder: (context, state) {
// return _Timer(
// timeLeft: state.timeLeft,
// duration: state.duration,
// );
// },
// ),
// ),
BlocBuilder<TimerBloc, TimerState>(
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<TimerBloc, TimerState>(
buildWhen: (previous, current) => previous.timeLeft != current.timeLeft,
builder: (_, state) => _Timer(
timeLeft: state.timeLeft,
duration: state.duration,
),
),
),
),
const Spacer(),
BlocBuilder<TimerBloc, TimerState>(
builder: (_, state) => FloatingActionButton(
@ -120,8 +121,10 @@ class _TimerScreenState extends State<TimerScreen> with TickerProviderStateMixin
switch (state) {
case TimerResumedState():
startStopIconController.forward();
timelineController.forward();
case TimerStoppedState():
startStopIconController.reverse();
timelineController.stop();
}
}
}