From 02ffb9b2f759e8d1bfba55ec1cb386b20851bf17 Mon Sep 17 00:00:00 2001 From: Crondung <1922635@stud.hs-mannheim.de> Date: Sun, 26 Feb 2023 17:33:32 +0100 Subject: [PATCH] wip refactor timer --- lib/pages/interval_page.dart | 103 ++++++++++++---------- lib/widgets/popup_for_start_and_stop.dart | 23 +---- lib/widgets/timer_widget.dart | 0 3 files changed, 59 insertions(+), 67 deletions(-) create mode 100644 lib/widgets/timer_widget.dart diff --git a/lib/pages/interval_page.dart b/lib/pages/interval_page.dart index 619d969..98b1c17 100644 --- a/lib/pages/interval_page.dart +++ b/lib/pages/interval_page.dart @@ -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 { 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 { @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(); + } + }, + ), + // ), + ], + ), + ], + ))); } } diff --git a/lib/widgets/popup_for_start_and_stop.dart b/lib/widgets/popup_for_start_and_stop.dart index 5221541..e1af268 100644 --- a/lib/widgets/popup_for_start_and_stop.dart +++ b/lib/widgets/popup_for_start_and_stop.dart @@ -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 { - 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)), ], ), ); diff --git a/lib/widgets/timer_widget.dart b/lib/widgets/timer_widget.dart new file mode 100644 index 0000000..e69de29