From 6ed9c239011dc34c18adef68824775c5208e64b4 Mon Sep 17 00:00:00 2001 From: Parricc35 <63447810+Parricc35@users.noreply.github.com> Date: Sun, 26 Feb 2023 00:32:58 +0100 Subject: [PATCH 1/3] music is working on a android phone --- lib/pages/interval_page.dart | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/pages/interval_page.dart b/lib/pages/interval_page.dart index 8239d09..619d969 100644 --- a/lib/pages/interval_page.dart +++ b/lib/pages/interval_page.dart @@ -11,14 +11,15 @@ class IntervalTimerPage extends StatefulWidget { } class _IntervalTimerPageState extends State { - final Duration _warmupDuration = const Duration(minutes: 5); - final Duration _cooldownDuration = const Duration(minutes: 5); - final Duration _highIntensityDuration = const Duration(minutes: 4); - final Duration _lowIntensityDuration = const Duration(minutes: 3); + final Duration _warmupDuration = const Duration(seconds: 5); + final Duration _cooldownDuration = const Duration(seconds: 5); + final Duration _highIntensityDuration = const Duration(seconds: 4); + final Duration _lowIntensityDuration = const Duration(seconds: 3); late Duration _totalDuration = const Duration(minutes: 35); AudioPlayer warmUpPlayer = AudioPlayer(); AudioPlayer workoutPlayer = AudioPlayer(); AudioPlayer coolDownPlayer = AudioPlayer(); + final AudioCache _audioCache = AudioCache(); final int _numHighIntensityBlocks = 4; final int _numLowIntensityBlocks = 3; @@ -49,7 +50,8 @@ class _IntervalTimerPageState extends State { }, ); _isPaused = false; - await AudioPlayer().play(UrlSource('assets/go.mp3')); + Source source = AssetSource('go.mp3'); + await AudioPlayer().play(source); _timer = Timer.periodic(const Duration(seconds: 1), (_) => _tick()); Future.delayed(const Duration(seconds: 1)).then((value) { @@ -80,20 +82,23 @@ class _IntervalTimerPageState extends State { } Future _playWarmUpMusic() async { + Source source = AssetSource('warmUp.mp3'); await warmUpPlayer.setReleaseMode(ReleaseMode.loop); - await warmUpPlayer.play(UrlSource('assets/warmUp.mp3')); + await warmUpPlayer.play(source); } Future _playWorkoutMusic() async { await warmUpPlayer.stop(); Future.delayed(const Duration(microseconds: 600)).then((value) async { + Source source = AssetSource('workout.mp3'); await workoutPlayer.setReleaseMode(ReleaseMode.loop); - await workoutPlayer.play(UrlSource('assets/workout.mp3')); + await workoutPlayer.play(source); }); } Future _intervalChange() async { - await AudioPlayer().play(UrlSource('assets/beep.mp3')); + Source source = AssetSource('beep.mp3'); + await AudioPlayer().play(source); } void _tick() { @@ -123,14 +128,16 @@ class _IntervalTimerPageState extends State { _currentDuration = _cooldownDuration; () async { await workoutPlayer.stop(); + Source source = AssetSource('cool_down.mp3'); await coolDownPlayer.setReleaseMode(ReleaseMode.loop); - await coolDownPlayer.play(UrlSource('assets/cool_down.mp3')); + await coolDownPlayer.play(source); }(); } else { () async { Future.delayed(const Duration(microseconds: 900)) .then((value) async { - await AudioPlayer().play(UrlSource('assets/finish.mp3')); + Source source = AssetSource('finish.mp3'); + await AudioPlayer().play(source); }); }(); _resetTimer(); From 449230e8d9c5e83626fdff95d8047dc260439c64 Mon Sep 17 00:00:00 2001 From: Crondung <1922635@stud.hs-mannheim.de> Date: Sun, 26 Feb 2023 10:44:16 +0100 Subject: [PATCH 2/3] fix slider bug --- lib/widgets/mood_form.dart | 2 +- lib/widgets/popup_for_start_and_stop.dart | 6 +++--- lib/widgets/sleep_form.dart | 2 +- lib/widgets/slider.dart | 20 ++++++++++---------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/widgets/mood_form.dart b/lib/widgets/mood_form.dart index e7e425b..78c3e43 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 = 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 index 097e587..84f5383 100644 --- a/lib/widgets/popup_for_start_and_stop.dart +++ b/lib/widgets/popup_for_start_and_stop.dart @@ -13,7 +13,7 @@ class TimerStartStopPopup extends StatefulWidget { } class TimerStartStopPopupState extends State { - final MySlider slider = const MySlider(); + final MySlider slider = MySlider(); void submitForm(BuildContext context) { Navigator.of(context).pop(); @@ -29,8 +29,8 @@ class TimerStartStopPopupState extends State { mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [ - const Padding( - padding: EdgeInsets.only(top: 8), + Padding( + padding: const EdgeInsets.only(top: 8), child: MySlider(labelText: 'Motivation'), ), const SizedBox(height: 16), diff --git a/lib/widgets/sleep_form.dart b/lib/widgets/sleep_form.dart index 32aab4d..5f8b9bd 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 = 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 02f3fb8..0102014 100644 --- a/lib/widgets/slider.dart +++ b/lib/widgets/slider.dart @@ -1,10 +1,9 @@ import 'package:flutter/material.dart'; -double _currentSliderValue = 50; - class MySlider extends StatefulWidget { + double _currentSliderValue = 50; final String _labelText; - const MySlider({Key? key, String labelText = 'Stimmung'}) + MySlider({Key? key, String labelText = 'Stimmung'}) : _labelText = labelText, super(key: key); @@ -23,7 +22,7 @@ class SliderState extends State { @override void initState() { super.initState(); - _textFieldController.text = _currentSliderValue.toStringAsFixed(0); + _textFieldController.text = widget._currentSliderValue.toStringAsFixed(0); } @override @@ -38,15 +37,16 @@ class SliderState extends State { children: [ Expanded( child: Slider( - value: _currentSliderValue, + value: widget._currentSliderValue, min: 1, max: 100, divisions: 99, - label: _currentSliderValue.round().toString(), + label: widget._currentSliderValue.round().toString(), onChanged: (double value) { setState(() { - _currentSliderValue = value; - _textFieldController.text = _currentSliderValue.toStringAsFixed(0); + widget._currentSliderValue = value; + _textFieldController.text = + widget._currentSliderValue.toStringAsFixed(0); _errorText = null; }); }, @@ -65,7 +65,7 @@ class SliderState extends State { onChanged: (text) { if (text.isEmpty) { setState(() { - _currentSliderValue = 1; + widget._currentSliderValue = 1; _textFieldController.clear(); _errorText = null; }); @@ -80,7 +80,7 @@ class SliderState extends State { return; } setState(() { - _currentSliderValue = value; + widget._currentSliderValue = value; _errorText = null; }); }, From f89fb41397c1c0a3ec8542bb8b44e2b9adfb29a3 Mon Sep 17 00:00:00 2001 From: Crondung <1922635@stud.hs-mannheim.de> Date: Sun, 26 Feb 2023 11:30:24 +0100 Subject: [PATCH 3/3] add iconbuttons to change slider value --- lib/widgets/mood_form.dart | 2 +- lib/widgets/popup_for_start_and_stop.dart | 2 +- lib/widgets/sleep_form.dart | 2 +- lib/widgets/slider.dart | 78 +++++++---------------- 4 files changed, 26 insertions(+), 58 deletions(-) diff --git a/lib/widgets/mood_form.dart b/lib/widgets/mood_form.dart index 78c3e43..6447a0d 100644 --- a/lib/widgets/mood_form.dart +++ b/lib/widgets/mood_form.dart @@ -22,7 +22,7 @@ class _MoodFormState extends State { _moodFormKey.currentState?.save(); //call every onSave Method //TODO Businesslogik aufrufen! print(_textInput); - print(slider.getSliderValue()); + print(slider.sliderValue); _moodFormKey.currentState?.reset(); } } diff --git a/lib/widgets/popup_for_start_and_stop.dart b/lib/widgets/popup_for_start_and_stop.dart index 84f5383..b8ed90a 100644 --- a/lib/widgets/popup_for_start_and_stop.dart +++ b/lib/widgets/popup_for_start_and_stop.dart @@ -31,7 +31,7 @@ class TimerStartStopPopupState extends State { children: [ Padding( padding: const EdgeInsets.only(top: 8), - child: MySlider(labelText: 'Motivation'), + child: MySlider(), ), const SizedBox(height: 16), MyTextFormField('Beschreibe deinen Motivation', onFormFieldSave), diff --git a/lib/widgets/sleep_form.dart b/lib/widgets/sleep_form.dart index 5f8b9bd..ba1259c 100644 --- a/lib/widgets/sleep_form.dart +++ b/lib/widgets/sleep_form.dart @@ -28,7 +28,7 @@ class _SleepFormState extends State { _sleepFormKey.currentState?.save(); //call every onSave Method //TODO Businesslogik aufrufen! print(_textInput); - print(slider.getSliderValue()); + print(slider.sliderValue); print('Eingeschlafen um: ${sleepTimePicker.getCurrentTime}'); _sleepFormKey.currentState?.reset(); } diff --git a/lib/widgets/slider.dart b/lib/widgets/slider.dart index 0102014..b642916 100644 --- a/lib/widgets/slider.dart +++ b/lib/widgets/slider.dart @@ -1,90 +1,58 @@ import 'package:flutter/material.dart'; +// ignore: must_be_immutable class MySlider extends StatefulWidget { double _currentSliderValue = 50; - final String _labelText; - MySlider({Key? key, String labelText = 'Stimmung'}) - : _labelText = labelText, - super(key: key); + MySlider({Key? key}) : super(key: key); @override State createState() => SliderState(); - double getSliderValue() { - return _currentSliderValue; - } + double get sliderValue => _currentSliderValue; } class SliderState extends State { - TextEditingController _textFieldController = TextEditingController(); - String? _errorText; - - @override - void initState() { - super.initState(); - _textFieldController.text = widget._currentSliderValue.toStringAsFixed(0); - } - @override Widget build(BuildContext context) { return Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - SizedBox(height: 16), + const SizedBox(height: 16), + Text('${widget._currentSliderValue.toInt()}', + style: const TextStyle(fontSize: 22)), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ + IconButton( + icon: const Icon(Icons.remove_outlined), + onPressed: () { + setState(() { + widget._currentSliderValue -= 1; + }); + }, + ), Expanded( child: Slider( value: widget._currentSliderValue, - min: 1, + min: 0, max: 100, - divisions: 99, + divisions: 100, label: widget._currentSliderValue.round().toString(), onChanged: (double value) { setState(() { widget._currentSliderValue = value; - _textFieldController.text = - widget._currentSliderValue.toStringAsFixed(0); - _errorText = null; }); }, ), ), - SizedBox(width: 16), - SizedBox( - width: 100, - child: TextFormField( - controller: _textFieldController, - keyboardType: TextInputType.number, - decoration: InputDecoration( - labelText: widget._labelText, - errorText: _errorText, - ), - onChanged: (text) { - if (text.isEmpty) { - setState(() { - widget._currentSliderValue = 1; - _textFieldController.clear(); - _errorText = null; - }); - return; - } - final value = double.tryParse(text); - if (value == null || value < 1 || value > 100) { - setState(() { - _textFieldController.clear(); - _errorText = 'Please enter a value between 1 and 100.'; - }); - return; - } - setState(() { - widget._currentSliderValue = value; - _errorText = null; - }); - }, - ), + IconButton( + icon: const Icon(Icons.add_outlined), + onPressed: () { + setState(() { + widget._currentSliderValue += 1; + }); + }, ), ], ),