From 4700f52646bee18b2715341d002600c5e1a2e372 Mon Sep 17 00:00:00 2001 From: Parricc35 <63447810+Parricc35@users.noreply.github.com> Date: Tue, 21 Feb 2023 22:33:03 +0100 Subject: [PATCH 1/4] Created Popup for start and stop timer --- lib/pages/interval_page.dart | 26 +++++++++++-- lib/widgets/elevated_card.dart | 8 ++-- lib/widgets/mood_form.dart | 2 +- lib/widgets/popup_for_start_and_stop.dart | 46 +++++++++++++++++++++++ lib/widgets/sleep_form.dart | 2 +- lib/widgets/slider.dart | 9 +++-- 6 files changed, 79 insertions(+), 14 deletions(-) create mode 100644 lib/widgets/popup_for_start_and_stop.dart diff --git a/lib/pages/interval_page.dart b/lib/pages/interval_page.dart index a712243..04a0f49 100644 --- a/lib/pages/interval_page.dart +++ b/lib/pages/interval_page.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:audioplayers/audioplayers.dart'; import 'package:flutter/material.dart'; +import 'package:smoke_cess_app/widgets/popup_for_start_and_stop.dart'; class IntervalTimerPage extends StatefulWidget { const IntervalTimerPage({Key? key}) : super(key: key); @@ -38,11 +39,19 @@ class _IntervalTimerPageState extends State { super.dispose(); } - void _startTimer() { + void _startTimer() async { + await showDialog( + context: context, + builder: (BuildContext context) { + return const StartTimerPopup( + title: 'Motivation vor dem Training', + text: 'Du gehörst zu Gruppe', + ); + }, + ); _isPaused = false; - () async { - await AudioPlayer().play(UrlSource('assets/go.mp3')); - }(); + await AudioPlayer().play(UrlSource('assets/go.mp3')); + _timer = Timer.periodic(const Duration(seconds: 1), (_) => _tick()); Future.delayed(const Duration(seconds: 1)).then((value) { _playWarmUpMusic(); @@ -61,6 +70,15 @@ class _IntervalTimerPageState extends State { _currentDuration = _warmupDuration; _totalDuration = const Duration(minutes: 35); setState(() {}); + showDialog( + context: context, + builder: (BuildContext context) { + return const StartTimerPopup( + title: 'Motivation nach dem Training', + text: 'Du gehörst zu Gruppe', + ); + }, + ); } Future _playWarmUpMusic() async { diff --git a/lib/widgets/elevated_card.dart b/lib/widgets/elevated_card.dart index eba4532..004b837 100644 --- a/lib/widgets/elevated_card.dart +++ b/lib/widgets/elevated_card.dart @@ -18,18 +18,18 @@ class ElevatedCard extends StatelessWidget { borderRadius: BorderRadius.circular(16.0), ), child: Padding( - padding: const EdgeInsets.all(16.0), + padding: const EdgeInsets.all(14.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( title, - style: TextStyle( - fontSize: 18.0, + style: const TextStyle( + fontSize: 16.0, fontWeight: FontWeight.bold, ), ), - SizedBox(height: 8.0), + const SizedBox(height: 8.0), child, ], ), diff --git a/lib/widgets/mood_form.dart b/lib/widgets/mood_form.dart index a5c059f..e7e425b 100644 --- a/lib/widgets/mood_form.dart +++ b/lib/widgets/mood_form.dart @@ -14,7 +14,7 @@ class MoodForm extends StatefulWidget { class _MoodFormState extends State { final GlobalKey _moodFormKey = GlobalKey(); - MySlider slider = const MySlider(''); + MySlider slider = const MySlider(); String _textInput = ""; void submitForm() { diff --git a/lib/widgets/popup_for_start_and_stop.dart b/lib/widgets/popup_for_start_and_stop.dart new file mode 100644 index 0000000..b51baff --- /dev/null +++ b/lib/widgets/popup_for_start_and_stop.dart @@ -0,0 +1,46 @@ +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 StartTimerPopup extends StatefulWidget { + final String title; + final String text; + + const StartTimerPopup({Key? key, required this.title, required this.text}) + : super(key: key); + + @override + _StartTimerPopupState createState() => _StartTimerPopupState(); +} + +class _StartTimerPopupState extends State { + final MySlider slider = const MySlider(); + String _textInput = ''; + + void submitForm(BuildContext context) { + Navigator.of(context).pop(); + } + + void onFormFieldSave(String? newValue) => _textInput = newValue!; + + @override + Widget build(BuildContext context) { + return AlertDialog( + title: Text(widget.title), + content: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Padding( + padding: EdgeInsets.only(top: 8), + child: MySlider(labelText: 'Motivation'), + ), + const SizedBox(height: 16), + MyTextFormField('Beschreibe deinen Motivation', onFormFieldSave), + SubmitFormButton(() => submitForm(context)), + ], + ), + ); + } +} diff --git a/lib/widgets/sleep_form.dart b/lib/widgets/sleep_form.dart index 52eefe8..32aab4d 100644 --- a/lib/widgets/sleep_form.dart +++ b/lib/widgets/sleep_form.dart @@ -14,7 +14,7 @@ class SleepForm extends StatefulWidget { class _SleepFormState extends State { final GlobalKey _sleepFormKey = GlobalKey(); - MySlider slider = const MySlider(''); + MySlider slider = const MySlider(); String _textInput = ""; TimePicker sleepTimePicker = TimePicker( const TimeOfDay(hour: 22, minute: 00), diff --git a/lib/widgets/slider.dart b/lib/widgets/slider.dart index 9d896b7..02f3fb8 100644 --- a/lib/widgets/slider.dart +++ b/lib/widgets/slider.dart @@ -3,8 +3,10 @@ import 'package:flutter/material.dart'; double _currentSliderValue = 50; class MySlider extends StatefulWidget { - final String _title; - const MySlider(this._title, {Key? key}) : super(key: key); + final String _labelText; + const MySlider({Key? key, String labelText = 'Stimmung'}) + : _labelText = labelText, + super(key: key); @override State createState() => SliderState(); @@ -30,7 +32,6 @@ class SliderState extends State { child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - Text(widget._title), SizedBox(height: 16), Row( mainAxisAlignment: MainAxisAlignment.center, @@ -58,7 +59,7 @@ class SliderState extends State { controller: _textFieldController, keyboardType: TextInputType.number, decoration: InputDecoration( - labelText: 'Stimmung', + labelText: widget._labelText, errorText: _errorText, ), onChanged: (text) { From 37b941cdd1fde71131516f43c5480405c00dc111 Mon Sep 17 00:00:00 2001 From: Crondung <1922635@stud.hs-mannheim.de> Date: Tue, 21 Feb 2023 23:28:31 +0100 Subject: [PATCH 2/4] enable timer to replay music --- lib/pages/interval_page.dart | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/pages/interval_page.dart b/lib/pages/interval_page.dart index 04a0f49..973c269 100644 --- a/lib/pages/interval_page.dart +++ b/lib/pages/interval_page.dart @@ -60,9 +60,9 @@ class _IntervalTimerPageState extends State { void _resetTimer() { () async { - await coolDownPlayer.dispose(); - await warmUpPlayer.dispose(); - await workoutPlayer.dispose(); + await coolDownPlayer.stop(); + await warmUpPlayer.stop(); + await workoutPlayer.stop(); }(); _isPaused = true; _timer?.cancel(); @@ -87,7 +87,7 @@ class _IntervalTimerPageState extends State { } Future _playWorkoutMusic() async { - await warmUpPlayer.dispose(); + await warmUpPlayer.stop(); Future.delayed(const Duration(microseconds: 600)).then((value) async { await workoutPlayer.play(UrlSource('assets/workout.mp3')); }); @@ -123,7 +123,7 @@ class _IntervalTimerPageState extends State { _currentBlock++; _currentDuration = _cooldownDuration; () async { - await workoutPlayer.dispose(); + await workoutPlayer.stop(); await coolDownPlayer.play(UrlSource('assets/cool_down.mp3')); }(); } else { From c0eec7e23dd23304780045ac6e6ff440b5daf6c7 Mon Sep 17 00:00:00 2001 From: Parricc35 <63447810+Parricc35@users.noreply.github.com> Date: Wed, 22 Feb 2023 13:23:17 +0100 Subject: [PATCH 3/4] I dont get it but it is working with loop --- lib/pages/interval_page.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/pages/interval_page.dart b/lib/pages/interval_page.dart index 973c269..3a7eabf 100644 --- a/lib/pages/interval_page.dart +++ b/lib/pages/interval_page.dart @@ -89,6 +89,7 @@ class _IntervalTimerPageState extends State { Future _playWorkoutMusic() async { await warmUpPlayer.stop(); Future.delayed(const Duration(microseconds: 600)).then((value) async { + await workoutPlayer.setReleaseMode(ReleaseMode.loop); await workoutPlayer.play(UrlSource('assets/workout.mp3')); }); } @@ -124,6 +125,7 @@ class _IntervalTimerPageState extends State { _currentDuration = _cooldownDuration; () async { await workoutPlayer.stop(); + await coolDownPlayer.setReleaseMode(ReleaseMode.loop); await coolDownPlayer.play(UrlSource('assets/cool_down.mp3')); }(); } else { From b6c3c2e7a722b80a7229b6537244d4008edacab1 Mon Sep 17 00:00:00 2001 From: Parricc35 <63447810+Parricc35@users.noreply.github.com> Date: Wed, 22 Feb 2023 13:32:23 +0100 Subject: [PATCH 4/4] Reworked Commends --- lib/pages/interval_page.dart | 6 ++---- lib/widgets/popup_for_start_and_stop.dart | 13 +++++-------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/lib/pages/interval_page.dart b/lib/pages/interval_page.dart index 04a0f49..26bf35b 100644 --- a/lib/pages/interval_page.dart +++ b/lib/pages/interval_page.dart @@ -43,9 +43,8 @@ class _IntervalTimerPageState extends State { await showDialog( context: context, builder: (BuildContext context) { - return const StartTimerPopup( + return const TimerStartStopPopup( title: 'Motivation vor dem Training', - text: 'Du gehörst zu Gruppe', ); }, ); @@ -73,9 +72,8 @@ class _IntervalTimerPageState extends State { showDialog( context: context, builder: (BuildContext context) { - return const StartTimerPopup( + return const TimerStartStopPopup( title: 'Motivation nach dem Training', - text: 'Du gehörst zu Gruppe', ); }, ); diff --git a/lib/widgets/popup_for_start_and_stop.dart b/lib/widgets/popup_for_start_and_stop.dart index b51baff..097e587 100644 --- a/lib/widgets/popup_for_start_and_stop.dart +++ b/lib/widgets/popup_for_start_and_stop.dart @@ -3,26 +3,23 @@ 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 StartTimerPopup extends StatefulWidget { +class TimerStartStopPopup extends StatefulWidget { final String title; - final String text; - const StartTimerPopup({Key? key, required this.title, required this.text}) - : super(key: key); + const TimerStartStopPopup({Key? key, required this.title}) : super(key: key); @override - _StartTimerPopupState createState() => _StartTimerPopupState(); + TimerStartStopPopupState createState() => TimerStartStopPopupState(); } -class _StartTimerPopupState extends State { +class TimerStartStopPopupState extends State { final MySlider slider = const MySlider(); - String _textInput = ''; void submitForm(BuildContext context) { Navigator.of(context).pop(); } - void onFormFieldSave(String? newValue) => _textInput = newValue!; + void onFormFieldSave(String? newValue) => newValue!; @override Widget build(BuildContext context) {