Update when submiting form
parent
d18bf8f56d
commit
e8a123413c
|
@ -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<InputProvider>();
|
||||
var tasksModel = context.watch<TasksProvider>();
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
|
@ -30,6 +33,7 @@ class MoodForm extends StatelessWidget {
|
|||
),
|
||||
SubmitFormButton(
|
||||
submitCallback: inputModel.saveMood,
|
||||
updateTasks: () => tasksModel.setTaksDone(Pages.mood),
|
||||
)
|
||||
],
|
||||
);
|
||||
|
|
|
@ -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<InputProvider>();
|
||||
var settingsModel = context.watch<SettingsProvider>();
|
||||
var tasksModel = context.watch<TasksProvider>();
|
||||
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),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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<InputProvider>();
|
||||
TasksProvider tasksModel = context.watch<TasksProvider>();
|
||||
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),
|
||||
)
|
||||
],
|
||||
);
|
||||
|
|
|
@ -3,7 +3,9 @@ import 'package:flutter/material.dart';
|
|||
|
||||
class SubmitFormButton extends StatelessWidget {
|
||||
final Future<int> 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(
|
||||
if (success != 0) {
|
||||
AwesomeDialog(
|
||||
context: context,
|
||||
dialogType: DialogType.success,
|
||||
title: 'Gespeichert',
|
||||
desc: 'Der Eintrag wurde erfolgreich gespeichert',
|
||||
).show()
|
||||
: AwesomeDialog(
|
||||
).show();
|
||||
updateTasks();
|
||||
} else {
|
||||
AwesomeDialog(
|
||||
context: context,
|
||||
dialogType: DialogType.error,
|
||||
title: 'Fehler',
|
||||
desc: 'Der Eintrag konnte nicht gespeichert werden',
|
||||
).show();
|
||||
}
|
||||
},
|
||||
child: const Text('Speichern'),
|
||||
),
|
||||
|
|
Loading…
Reference in New Issue