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

View File

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

View File