From e8a123413c9959b26f083aaaca20dced75910bba Mon Sep 17 00:00:00 2001 From: "k.mannweiler" <2012491@stud.hs-mannheim.de> Date: Thu, 2 Mar 2023 20:16:46 +0100 Subject: [PATCH] Update when submiting form --- lib/widgets/mood_form.dart | 4 ++++ lib/widgets/relapse_form.dart | 9 ++++++-- lib/widgets/sleep_form.dart | 4 ++++ lib/widgets/submit_form_button.dart | 33 +++++++++++++++++------------ 4 files changed, 34 insertions(+), 16 deletions(-) diff --git a/lib/widgets/mood_form.dart b/lib/widgets/mood_form.dart index b461ce7..4661678 100644 --- a/lib/widgets/mood_form.dart +++ b/lib/widgets/mood_form.dart @@ -1,5 +1,7 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; +import 'package:smoke_cess_app/providers/tasks_provider.dart'; +import 'package:smoke_cess_app/services/pages_service.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'; @@ -13,6 +15,7 @@ class MoodForm extends StatelessWidget { @override Widget build(BuildContext context) { var inputModel = context.watch(); + var tasksModel = context.watch(); return Column( mainAxisAlignment: MainAxisAlignment.center, children: [ @@ -30,6 +33,7 @@ class MoodForm extends StatelessWidget { ), SubmitFormButton( submitCallback: inputModel.saveMood, + updateTasks: () => tasksModel.setTaksDone(Pages.mood), ) ], ); diff --git a/lib/widgets/relapse_form.dart b/lib/widgets/relapse_form.dart index 88e555c..38d3492 100644 --- a/lib/widgets/relapse_form.dart +++ b/lib/widgets/relapse_form.dart @@ -1,11 +1,12 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; +import 'package:smoke_cess_app/providers/tasks_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'; import '../providers/settings_provider.dart'; +import '../services/pages_service.dart'; import 'elevated_card.dart'; class RelapseForm extends StatelessWidget { @@ -15,6 +16,7 @@ class RelapseForm extends StatelessWidget { Widget build(BuildContext context) { var inputModel = context.watch(); var settingsModel = context.watch(); + var tasksModel = context.watch(); return Column( mainAxisAlignment: MainAxisAlignment.center, children: [ @@ -29,7 +31,10 @@ class RelapseForm extends StatelessWidget { const SizedBox( height: 80, ), - SubmitFormButton(submitCallback: inputModel.saveRelapse) + SubmitFormButton( + submitCallback: inputModel.saveRelapse, + updateTasks: () => tasksModel.setTaksDone(Pages.mood), + ) ], ); } diff --git a/lib/widgets/sleep_form.dart b/lib/widgets/sleep_form.dart index 8b4389c..b578e2c 100644 --- a/lib/widgets/sleep_form.dart +++ b/lib/widgets/sleep_form.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; +import 'package:smoke_cess_app/providers/tasks_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'; @@ -7,6 +8,7 @@ import 'package:smoke_cess_app/widgets/text_formfield.dart'; import 'package:smoke_cess_app/widgets/timepicker.dart'; import '../providers/input_provider.dart'; +import '../services/pages_service.dart'; class SleepForm extends StatelessWidget { const SleepForm({Key? key}) : super(key: key); @@ -14,6 +16,7 @@ class SleepForm extends StatelessWidget { @override Widget build(BuildContext context) { InputProvider inputModel = context.watch(); + TasksProvider tasksModel = context.watch(); String wokeUpKey = 'wokeUpAt'; String sleptKey = 'sleptAt'; @@ -44,6 +47,7 @@ class SleepForm extends StatelessWidget { ), SubmitFormButton( submitCallback: () => inputModel.saveSleep(wokeUpKey, sleptKey), + updateTasks: () => tasksModel.setTaksDone(Pages.mood), ) ], ); diff --git a/lib/widgets/submit_form_button.dart b/lib/widgets/submit_form_button.dart index 3242b18..b5bb593 100644 --- a/lib/widgets/submit_form_button.dart +++ b/lib/widgets/submit_form_button.dart @@ -3,7 +3,9 @@ import 'package:flutter/material.dart'; class SubmitFormButton extends StatelessWidget { final Future Function() submitCallback; - const SubmitFormButton({super.key, required this.submitCallback}); + final void Function() updateTasks; + const SubmitFormButton( + {super.key, required this.submitCallback, required this.updateTasks}); @override Widget build(BuildContext context) { @@ -12,19 +14,22 @@ class SubmitFormButton extends StatelessWidget { child: ElevatedButton( onPressed: () async { int success = await submitCallback(); - success != 0 - ? AwesomeDialog( - context: context, - dialogType: DialogType.success, - title: 'Gespeichert', - desc: 'Der Eintrag wurde erfolgreich gespeichert', - ).show() - : AwesomeDialog( - context: context, - dialogType: DialogType.error, - title: 'Fehler', - desc: 'Der Eintrag konnte nicht gespeichert werden', - ).show(); + if (success != 0) { + AwesomeDialog( + context: context, + dialogType: DialogType.success, + title: 'Gespeichert', + desc: 'Der Eintrag wurde erfolgreich gespeichert', + ).show(); + updateTasks(); + } else { + AwesomeDialog( + context: context, + dialogType: DialogType.error, + title: 'Fehler', + desc: 'Der Eintrag konnte nicht gespeichert werden', + ).show(); + } }, child: const Text('Speichern'), ),