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';
|
|
|
|
|
2023-03-01 13:30:12 +01:00
|
|
|
import '../providers/input_provider.dart';
|
2023-02-27 01:20:00 +01:00
|
|
|
import '../providers/timer_provider.dart';
|
2023-03-01 13:30:12 +01:00
|
|
|
import 'popup_for_start_and_stop.dart';
|
2023-02-27 01:20:00 +01:00
|
|
|
|
|
|
|
class WorkoutTimerWidget extends StatelessWidget {
|
|
|
|
const WorkoutTimerWidget({super.key});
|
|
|
|
|
2023-03-01 13:30:12 +01:00
|
|
|
void _onStartButtonPressed(BuildContext context) {}
|
|
|
|
|
2023-02-27 01:20:00 +01:00
|
|
|
@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:57:02 +01:00
|
|
|
const SizedBox(
|
|
|
|
height: 20,
|
|
|
|
),
|
|
|
|
Stack(
|
|
|
|
alignment: Alignment.center,
|
|
|
|
children: [
|
|
|
|
SizedBox(
|
|
|
|
height: 100,
|
|
|
|
width: 100,
|
|
|
|
child: CircularProgressIndicator(
|
2023-03-01 13:07:01 +01:00
|
|
|
color: workoutProvider.currentPhaseColor,
|
2023-03-01 12:57:02 +01:00
|
|
|
value: (workoutProvider.currentPhaseDuration.inSeconds
|
|
|
|
.toDouble() -
|
|
|
|
timerProvider.elapsedSeconds) /
|
|
|
|
workoutProvider.currentPhaseDuration.inSeconds)),
|
|
|
|
TimerWidget(duration: workoutProvider.currentPhaseDuration),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 20,
|
|
|
|
),
|
2023-02-28 14:58:32 +01:00
|
|
|
ElevatedButton(
|
2023-02-28 15:07:47 +01:00
|
|
|
onPressed: !workoutProvider.isWorkoutStarted
|
2023-03-01 13:30:12 +01:00
|
|
|
? () async {
|
|
|
|
double sliderValue = await showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return ChangeNotifierProvider(
|
|
|
|
create: (context) => InputProvider(),
|
|
|
|
child: const TimerStartStopPopup(
|
|
|
|
title: 'Motivation vor dem Training',
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
print(sliderValue);
|
|
|
|
workoutProvider.startWorkout();
|
|
|
|
}
|
2023-02-28 15:07:47 +01:00
|
|
|
: () => workoutProvider.stopWorkout(),
|
2023-02-28 14:58:32 +01:00
|
|
|
child: Text(timerProvider.started ? 'Stop' : 'Start'))
|
2023-02-27 01:20:00 +01:00
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|