56 lines
1.8 KiB
Dart
56 lines
1.8 KiB
Dart
import 'dart:async';
|
|
|
|
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>();
|
|
|
|
if (workoutProvider.isPhaseComplete) {
|
|
Timer(const Duration(milliseconds: 1), () => workoutProvider.nextPhase());
|
|
}
|
|
|
|
return Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Text(workoutProvider.currentPhase),
|
|
const SizedBox(
|
|
height: 20,
|
|
),
|
|
Stack(
|
|
alignment: Alignment.center,
|
|
children: [
|
|
SizedBox(
|
|
height: 100,
|
|
width: 100,
|
|
child: CircularProgressIndicator(
|
|
color: workoutProvider.currentPhaseColor,
|
|
value: (workoutProvider.currentPhaseDuration.inSeconds
|
|
.toDouble() -
|
|
timerProvider.elapsedSeconds) /
|
|
workoutProvider.currentPhaseDuration.inSeconds)),
|
|
TimerWidget(duration: workoutProvider.currentPhaseDuration),
|
|
],
|
|
),
|
|
const SizedBox(
|
|
height: 20,
|
|
),
|
|
ElevatedButton(
|
|
onPressed: !workoutProvider.isWorkoutStarted
|
|
? () => workoutProvider.startWorkout()
|
|
: () => workoutProvider.stopWorkout(),
|
|
child: Text(timerProvider.started ? 'Stop' : 'Start'))
|
|
],
|
|
);
|
|
}
|
|
}
|