From 591317df260fdef4ed67f3637f657b0f061db176 Mon Sep 17 00:00:00 2001 From: "k.mannweiler" <2012491@stud.hs-mannheim.de> Date: Mon, 27 Feb 2023 20:09:11 +0100 Subject: [PATCH] Added Submitformbutton to sleep and relapse --- lib/providers/input_provider.dart | 8 ++++---- lib/widgets/relapse_form.dart | 6 ++---- lib/widgets/sleep_form.dart | 7 ++++--- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/providers/input_provider.dart b/lib/providers/input_provider.dart index 1f4fefd..a61514f 100644 --- a/lib/providers/input_provider.dart +++ b/lib/providers/input_provider.dart @@ -51,17 +51,17 @@ class InputProvider extends ChangeNotifier { return globals.databaseService.addMood(mood); } - void saveRelapse() { + Future saveRelapse() { Relapse relapse = Relapse(_relapseCategory, _textController.text, DateTime.now()); - globals.databaseService.addRelapse(relapse); _resetFields(); + return globals.databaseService.addRelapse(relapse); } - void saveSleep(String wokeUpKey, String sleptKey) { + Future saveSleep(String wokeUpKey, String sleptKey) { Sleep sleep = Sleep(_sliderValue.toInt(), _textController.text, DateTime.now(), getTimeEntry(sleptKey), getTimeEntry(wokeUpKey)); - globals.databaseService.addSleep(sleep); _resetFields(); + return globals.databaseService.addSleep(sleep); } } diff --git a/lib/widgets/relapse_form.dart b/lib/widgets/relapse_form.dart index a00ab31..88e555c 100644 --- a/lib/widgets/relapse_form.dart +++ b/lib/widgets/relapse_form.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:smoke_cess_app/widgets/drop_down.dart'; +import 'package:smoke_cess_app/widgets/submit_form_button.dart'; import 'package:smoke_cess_app/widgets/text_formfield.dart'; import '../providers/input_provider.dart'; @@ -28,10 +29,7 @@ class RelapseForm extends StatelessWidget { const SizedBox( height: 80, ), - ElevatedButton( - onPressed: () => inputModel.saveRelapse(), - child: const Text('Speichern'), - ) + SubmitFormButton(submitCallback: inputModel.saveRelapse) ], ); } diff --git a/lib/widgets/sleep_form.dart b/lib/widgets/sleep_form.dart index 5cb7352..8b4389c 100644 --- a/lib/widgets/sleep_form.dart +++ b/lib/widgets/sleep_form.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:smoke_cess_app/widgets/elevated_card.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'; import 'package:smoke_cess_app/widgets/timepicker.dart'; @@ -41,9 +42,9 @@ class SleepForm extends StatelessWidget { const SizedBox( height: 80, ), - ElevatedButton( - onPressed: () => inputModel.saveSleep(wokeUpKey, sleptKey), - child: const Text('Speichern')) + SubmitFormButton( + submitCallback: () => inputModel.saveSleep(wokeUpKey, sleptKey), + ) ], ); }