2023-02-28 13:05:51 +01:00
|
|
|
import 'dart:async';
|
|
|
|
|
2023-02-27 01:20:00 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:smoke_cess_app/providers/workout_provider.dart';
|
|
|
|
import 'package:smoke_cess_app/widgets/timer_widget.dart';
|
|
|
|
|
|
|
|
import '../providers/timer_provider.dart';
|
|
|
|
|
|
|
|
class WorkoutTimerWidget extends StatelessWidget {
|
|
|
|
const WorkoutTimerWidget({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
TimerProvider timerProvider = context.watch<TimerProvider>();
|
|
|
|
WorkoutProvider workoutProvider = context.watch<WorkoutProvider>();
|
|
|
|
|
2023-02-28 14:58:32 +01:00
|
|
|
if (workoutProvider.isPhaseComplete) {
|
2023-02-28 13:05:51 +01:00
|
|
|
Timer(const Duration(milliseconds: 1), () => workoutProvider.nextPhase());
|
2023-02-27 01:20:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Text(workoutProvider.currentPhase),
|
2023-03-01 12:34:35 +01:00
|
|
|
CircularProgressIndicator(
|
|
|
|
value: timerProvider.elapsedSeconds /
|
|
|
|
workoutProvider.currentPhaseDuration.inSeconds),
|
2023-02-28 14:58:32 +01:00
|
|
|
TimerWidget(duration: workoutProvider.currentPhaseDuration),
|
|
|
|
ElevatedButton(
|
2023-02-28 15:07:47 +01:00
|
|
|
onPressed: !workoutProvider.isWorkoutStarted
|
|
|
|
? () => workoutProvider.startWorkout()
|
|
|
|
: () => workoutProvider.stopWorkout(),
|
2023-02-28 14:58:32 +01:00
|
|
|
child: Text(timerProvider.started ? 'Stop' : 'Start'))
|
2023-02-27 01:20:00 +01:00
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|