Created Popup for start and stop timer

main
Parricc35 2023-02-21 22:33:03 +01:00
parent aabdaafadc
commit 4700f52646
6 changed files with 79 additions and 14 deletions

View File

@ -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<IntervalTimerPage> {
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'));
}();
_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<IntervalTimerPage> {
_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<void> _playWarmUpMusic() async {

View File

@ -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,
],
),

View File

@ -14,7 +14,7 @@ class MoodForm extends StatefulWidget {
class _MoodFormState extends State<MoodForm> {
final GlobalKey<FormState> _moodFormKey = GlobalKey<FormState>();
MySlider slider = const MySlider('');
MySlider slider = const MySlider();
String _textInput = "";
void submitForm() {

View File

@ -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<StartTimerPopup> {
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)),
],
),
);
}
}

View File

@ -14,7 +14,7 @@ class SleepForm extends StatefulWidget {
class _SleepFormState extends State<SleepForm> {
final GlobalKey<FormState> _sleepFormKey = GlobalKey<FormState>();
MySlider slider = const MySlider('');
MySlider slider = const MySlider();
String _textInput = "";
TimePicker sleepTimePicker = TimePicker(
const TimeOfDay(hour: 22, minute: 00),

View File

@ -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<StatefulWidget> createState() => SliderState();
@ -30,7 +32,6 @@ class SliderState extends State<MySlider> {
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(widget._title),
SizedBox(height: 16),
Row(
mainAxisAlignment: MainAxisAlignment.center,
@ -58,7 +59,7 @@ class SliderState extends State<MySlider> {
controller: _textFieldController,
keyboardType: TextInputType.number,
decoration: InputDecoration(
labelText: 'Stimmung',
labelText: widget._labelText,
errorText: _errorText,
),
onChanged: (text) {