wip refactor timer

main
Julian Gegner 2023-02-26 17:33:32 +01:00
parent 68033a64a5
commit 02ffb9b2f7
3 changed files with 59 additions and 67 deletions

View File

@ -1,8 +1,11 @@
import 'dart:async';
import 'package:audioplayers/audioplayers.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:smoke_cess_app/widgets/popup_for_start_and_stop.dart';
import '../providers/input_provider.dart';
class IntervalTimerPage extends StatefulWidget {
const IntervalTimerPage({Key? key}) : super(key: key);
@ -44,9 +47,11 @@ class _IntervalTimerPageState extends State<IntervalTimerPage> {
await showDialog(
context: context,
builder: (BuildContext context) {
return const TimerStartStopPopup(
title: 'Motivation vor dem Training',
);
return ChangeNotifierProvider(
create: (context) => InputProvider(),
child: const TimerStartStopPopup(
title: 'Motivation vor dem Training',
));
},
);
_isPaused = false;
@ -161,51 +166,53 @@ class _IntervalTimerPageState extends State<IntervalTimerPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
return Center(
child: ChangeNotifierProvider(
create: (context) => InputProvider(),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
_currentBlock == 0
? 'Warm-up'
: _currentBlock % 2 == 1
? 'High Intensity'
: _currentBlock < _numHighIntensityBlocks * 2
? 'Low Intensity'
: 'Cool-down',
style: const TextStyle(fontSize: 32.0),
),
const SizedBox(height: 16.0),
Text(
_formatDuration(_currentDuration),
style: const TextStyle(fontSize: 80.0),
),
const SizedBox(height: 32.0),
Text(
'Total: ${_formatTotalDuration(_totalDuration)}',
style: const TextStyle(fontSize: 24.0),
),
const SizedBox(height: 32.0),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
IconButton(
icon: Icon(
_isPaused ? Icons.play_arrow_rounded : Icons.stop_rounded),
iconSize: 48.0,
onPressed: () {
if (_isPaused) {
_startTimer();
} else {
_resetTimer();
}
},
),
// ),
],
),
],
)));
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
_currentBlock == 0
? 'Warm-up'
: _currentBlock % 2 == 1
? 'High Intensity'
: _currentBlock < _numHighIntensityBlocks * 2
? 'Low Intensity'
: 'Cool-down',
style: const TextStyle(fontSize: 32.0),
),
const SizedBox(height: 16.0),
Text(
_formatDuration(_currentDuration),
style: const TextStyle(fontSize: 80.0),
),
const SizedBox(height: 32.0),
Text(
'Total: ${_formatTotalDuration(_totalDuration)}',
style: const TextStyle(fontSize: 24.0),
),
const SizedBox(height: 32.0),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
IconButton(
icon: Icon(_isPaused
? Icons.play_arrow_rounded
: Icons.stop_rounded),
iconSize: 48.0,
onPressed: () {
if (_isPaused) {
_startTimer();
} else {
_resetTimer();
}
},
),
// ),
],
),
],
)));
}
}

View File

@ -1,41 +1,26 @@
import 'package:flutter/material.dart';
import 'package:smoke_cess_app/widgets/slider.dart';
import 'package:smoke_cess_app/widgets/submit_form_button.dart';
import 'package:smoke_cess_app/widgets/text_formfield.dart';
class TimerStartStopPopup extends StatefulWidget {
class TimerStartStopPopup extends StatelessWidget {
final String title;
const TimerStartStopPopup({Key? key, required this.title}) : super(key: key);
@override
TimerStartStopPopupState createState() => TimerStartStopPopupState();
}
class TimerStartStopPopupState extends State<TimerStartStopPopup> {
final MySlider slider = MySlider();
void submitForm(BuildContext context) {
Navigator.of(context).pop();
}
void onFormFieldSave(String? newValue) => newValue!;
@override
Widget build(BuildContext context) {
return AlertDialog(
title: Text(widget.title),
title: Text(title),
content: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
children: const [
Padding(
padding: const EdgeInsets.only(top: 8),
child: MySlider(),
),
const SizedBox(height: 16),
SizedBox(height: 16),
MyTextFormField('Beschreibe deinen Motivation'),
SubmitFormButton(() => submitForm(context)),
],
),
);

View File