return slider value after popup

main
Julian Gegner 2023-03-01 13:30:12 +01:00
parent 556daa9e90
commit cd88b483cf
3 changed files with 34 additions and 9 deletions

View File

@ -1,7 +1,6 @@
import 'dart:async';
import 'package:audioplayers/audioplayers.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:smoke_cess_app/providers/input_provider.dart';
import 'package:smoke_cess_app/providers/timer_provider.dart'; import 'package:smoke_cess_app/providers/timer_provider.dart';
import 'package:smoke_cess_app/providers/workout_provider.dart'; import 'package:smoke_cess_app/providers/workout_provider.dart';
import 'package:smoke_cess_app/widgets/mute_button.dart'; import 'package:smoke_cess_app/widgets/mute_button.dart';
@ -17,7 +16,7 @@ class IntervalTimerPage extends StatelessWidget {
providers: [ providers: [
ChangeNotifierProvider(create: (context) => timerProvider), ChangeNotifierProvider(create: (context) => timerProvider),
ChangeNotifierProvider( ChangeNotifierProvider(
create: (context) => WorkoutProvider(timerProvider)) create: (context) => WorkoutProvider(timerProvider)),
], ],
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,

View File

@ -1,4 +1,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:smoke_cess_app/providers/input_provider.dart';
import 'package:smoke_cess_app/widgets/slider.dart'; import 'package:smoke_cess_app/widgets/slider.dart';
import 'package:smoke_cess_app/widgets/text_formfield.dart'; import 'package:smoke_cess_app/widgets/text_formfield.dart';
@ -9,18 +11,24 @@ class TimerStartStopPopup extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
InputProvider inputProvider = context.watch<InputProvider>();
return AlertDialog( return AlertDialog(
title: Text(title), title: Text(title),
content: Column( content: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: const [ children: [
Padding( const Padding(
padding: const EdgeInsets.only(top: 8), padding: EdgeInsets.only(top: 8),
child: MySlider(), child: MySlider(),
), ),
SizedBox(height: 16), const SizedBox(height: 16),
MyTextFormField('Beschreibe deinen Motivation'), const MyTextFormField('Beschreibe deinen Motivation'),
ElevatedButton(
onPressed: () =>
Navigator.pop(context, inputProvider.sliderValue),
child: const Text('Speichern'))
], ],
), ),
); );

View File

@ -5,11 +5,15 @@ import 'package:provider/provider.dart';
import 'package:smoke_cess_app/providers/workout_provider.dart'; import 'package:smoke_cess_app/providers/workout_provider.dart';
import 'package:smoke_cess_app/widgets/timer_widget.dart'; import 'package:smoke_cess_app/widgets/timer_widget.dart';
import '../providers/input_provider.dart';
import '../providers/timer_provider.dart'; import '../providers/timer_provider.dart';
import 'popup_for_start_and_stop.dart';
class WorkoutTimerWidget extends StatelessWidget { class WorkoutTimerWidget extends StatelessWidget {
const WorkoutTimerWidget({super.key}); const WorkoutTimerWidget({super.key});
void _onStartButtonPressed(BuildContext context) {}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
TimerProvider timerProvider = context.watch<TimerProvider>(); TimerProvider timerProvider = context.watch<TimerProvider>();
@ -46,7 +50,21 @@ class WorkoutTimerWidget extends StatelessWidget {
), ),
ElevatedButton( ElevatedButton(
onPressed: !workoutProvider.isWorkoutStarted onPressed: !workoutProvider.isWorkoutStarted
? () => workoutProvider.startWorkout() ? () async {
double sliderValue = await showDialog(
context: context,
builder: (BuildContext context) {
return ChangeNotifierProvider(
create: (context) => InputProvider(),
child: const TimerStartStopPopup(
title: 'Motivation vor dem Training',
),
);
},
);
print(sliderValue);
workoutProvider.startWorkout();
}
: () => workoutProvider.stopWorkout(), : () => workoutProvider.stopWorkout(),
child: Text(timerProvider.started ? 'Stop' : 'Start')) child: Text(timerProvider.started ? 'Stop' : 'Start'))
], ],