Merge branch 'Timer-popup' into 'main'
Created Popup for start and stop timer See merge request Crondung/hsma_cpd!7main
commit
d2773cad54
|
@ -1,6 +1,7 @@
|
||||||
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:smoke_cess_app/widgets/popup_for_start_and_stop.dart';
|
||||||
|
|
||||||
class IntervalTimerPage extends StatefulWidget {
|
class IntervalTimerPage extends StatefulWidget {
|
||||||
const IntervalTimerPage({Key? key}) : super(key: key);
|
const IntervalTimerPage({Key? key}) : super(key: key);
|
||||||
|
@ -38,11 +39,18 @@ class _IntervalTimerPageState extends State<IntervalTimerPage> {
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _startTimer() {
|
void _startTimer() async {
|
||||||
|
await showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return const TimerStartStopPopup(
|
||||||
|
title: 'Motivation vor dem Training',
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
_isPaused = false;
|
_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());
|
_timer = Timer.periodic(const Duration(seconds: 1), (_) => _tick());
|
||||||
Future.delayed(const Duration(seconds: 1)).then((value) {
|
Future.delayed(const Duration(seconds: 1)).then((value) {
|
||||||
_playWarmUpMusic();
|
_playWarmUpMusic();
|
||||||
|
@ -51,9 +59,9 @@ class _IntervalTimerPageState extends State<IntervalTimerPage> {
|
||||||
|
|
||||||
void _resetTimer() {
|
void _resetTimer() {
|
||||||
() async {
|
() async {
|
||||||
await coolDownPlayer.dispose();
|
await coolDownPlayer.stop();
|
||||||
await warmUpPlayer.dispose();
|
await warmUpPlayer.stop();
|
||||||
await workoutPlayer.dispose();
|
await workoutPlayer.stop();
|
||||||
}();
|
}();
|
||||||
_isPaused = true;
|
_isPaused = true;
|
||||||
_timer?.cancel();
|
_timer?.cancel();
|
||||||
|
@ -61,6 +69,14 @@ class _IntervalTimerPageState extends State<IntervalTimerPage> {
|
||||||
_currentDuration = _warmupDuration;
|
_currentDuration = _warmupDuration;
|
||||||
_totalDuration = const Duration(minutes: 35);
|
_totalDuration = const Duration(minutes: 35);
|
||||||
setState(() {});
|
setState(() {});
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return const TimerStartStopPopup(
|
||||||
|
title: 'Motivation nach dem Training',
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _playWarmUpMusic() async {
|
Future<void> _playWarmUpMusic() async {
|
||||||
|
@ -69,8 +85,9 @@ class _IntervalTimerPageState extends State<IntervalTimerPage> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _playWorkoutMusic() async {
|
Future<void> _playWorkoutMusic() async {
|
||||||
await warmUpPlayer.dispose();
|
await warmUpPlayer.stop();
|
||||||
Future.delayed(const Duration(microseconds: 600)).then((value) async {
|
Future.delayed(const Duration(microseconds: 600)).then((value) async {
|
||||||
|
await workoutPlayer.setReleaseMode(ReleaseMode.loop);
|
||||||
await workoutPlayer.play(UrlSource('assets/workout.mp3'));
|
await workoutPlayer.play(UrlSource('assets/workout.mp3'));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -105,7 +122,8 @@ class _IntervalTimerPageState extends State<IntervalTimerPage> {
|
||||||
_currentBlock++;
|
_currentBlock++;
|
||||||
_currentDuration = _cooldownDuration;
|
_currentDuration = _cooldownDuration;
|
||||||
() async {
|
() async {
|
||||||
await workoutPlayer.dispose();
|
await workoutPlayer.stop();
|
||||||
|
await coolDownPlayer.setReleaseMode(ReleaseMode.loop);
|
||||||
await coolDownPlayer.play(UrlSource('assets/cool_down.mp3'));
|
await coolDownPlayer.play(UrlSource('assets/cool_down.mp3'));
|
||||||
}();
|
}();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -18,18 +18,18 @@ class ElevatedCard extends StatelessWidget {
|
||||||
borderRadius: BorderRadius.circular(16.0),
|
borderRadius: BorderRadius.circular(16.0),
|
||||||
),
|
),
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(16.0),
|
padding: const EdgeInsets.all(14.0),
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
title,
|
title,
|
||||||
style: TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 18.0,
|
fontSize: 16.0,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(height: 8.0),
|
const SizedBox(height: 8.0),
|
||||||
child,
|
child,
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
|
@ -14,7 +14,7 @@ class MoodForm extends StatefulWidget {
|
||||||
|
|
||||||
class _MoodFormState extends State<MoodForm> {
|
class _MoodFormState extends State<MoodForm> {
|
||||||
final GlobalKey<FormState> _moodFormKey = GlobalKey<FormState>();
|
final GlobalKey<FormState> _moodFormKey = GlobalKey<FormState>();
|
||||||
MySlider slider = const MySlider('');
|
MySlider slider = const MySlider();
|
||||||
String _textInput = "";
|
String _textInput = "";
|
||||||
|
|
||||||
void submitForm() {
|
void submitForm() {
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
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 {
|
||||||
|
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 = const 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),
|
||||||
|
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)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -14,7 +14,7 @@ class SleepForm extends StatefulWidget {
|
||||||
|
|
||||||
class _SleepFormState extends State<SleepForm> {
|
class _SleepFormState extends State<SleepForm> {
|
||||||
final GlobalKey<FormState> _sleepFormKey = GlobalKey<FormState>();
|
final GlobalKey<FormState> _sleepFormKey = GlobalKey<FormState>();
|
||||||
MySlider slider = const MySlider('');
|
MySlider slider = const MySlider();
|
||||||
String _textInput = "";
|
String _textInput = "";
|
||||||
TimePicker sleepTimePicker = TimePicker(
|
TimePicker sleepTimePicker = TimePicker(
|
||||||
const TimeOfDay(hour: 22, minute: 00),
|
const TimeOfDay(hour: 22, minute: 00),
|
||||||
|
|
|
@ -3,8 +3,10 @@ import 'package:flutter/material.dart';
|
||||||
double _currentSliderValue = 50;
|
double _currentSliderValue = 50;
|
||||||
|
|
||||||
class MySlider extends StatefulWidget {
|
class MySlider extends StatefulWidget {
|
||||||
final String _title;
|
final String _labelText;
|
||||||
const MySlider(this._title, {Key? key}) : super(key: key);
|
const MySlider({Key? key, String labelText = 'Stimmung'})
|
||||||
|
: _labelText = labelText,
|
||||||
|
super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<StatefulWidget> createState() => SliderState();
|
State<StatefulWidget> createState() => SliderState();
|
||||||
|
@ -30,7 +32,6 @@ class SliderState extends State<MySlider> {
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Text(widget._title),
|
|
||||||
SizedBox(height: 16),
|
SizedBox(height: 16),
|
||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
@ -58,7 +59,7 @@ class SliderState extends State<MySlider> {
|
||||||
controller: _textFieldController,
|
controller: _textFieldController,
|
||||||
keyboardType: TextInputType.number,
|
keyboardType: TextInputType.number,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: 'Stimmung',
|
labelText: widget._labelText,
|
||||||
errorText: _errorText,
|
errorText: _errorText,
|
||||||
),
|
),
|
||||||
onChanged: (text) {
|
onChanged: (text) {
|
||||||
|
|
Loading…
Reference in New Issue