Update when submiting form
parent
d18bf8f56d
commit
e8a123413c
|
@ -1,5 +1,7 @@
|
||||||
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/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/slider.dart';
|
||||||
import 'package:smoke_cess_app/widgets/submit_form_button.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/text_formfield.dart';
|
||||||
|
@ -13,6 +15,7 @@ class MoodForm extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var inputModel = context.watch<InputProvider>();
|
var inputModel = context.watch<InputProvider>();
|
||||||
|
var tasksModel = context.watch<TasksProvider>();
|
||||||
return Column(
|
return Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
|
@ -30,6 +33,7 @@ class MoodForm extends StatelessWidget {
|
||||||
),
|
),
|
||||||
SubmitFormButton(
|
SubmitFormButton(
|
||||||
submitCallback: inputModel.saveMood,
|
submitCallback: inputModel.saveMood,
|
||||||
|
updateTasks: () => tasksModel.setTaksDone(Pages.mood),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
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/tasks_provider.dart';
|
||||||
import 'package:smoke_cess_app/widgets/drop_down.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/submit_form_button.dart';
|
||||||
import 'package:smoke_cess_app/widgets/text_formfield.dart';
|
import 'package:smoke_cess_app/widgets/text_formfield.dart';
|
||||||
|
|
||||||
import '../providers/input_provider.dart';
|
import '../providers/input_provider.dart';
|
||||||
import '../providers/settings_provider.dart';
|
import '../providers/settings_provider.dart';
|
||||||
|
import '../services/pages_service.dart';
|
||||||
import 'elevated_card.dart';
|
import 'elevated_card.dart';
|
||||||
|
|
||||||
class RelapseForm extends StatelessWidget {
|
class RelapseForm extends StatelessWidget {
|
||||||
|
@ -15,6 +16,7 @@ class RelapseForm extends StatelessWidget {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var inputModel = context.watch<InputProvider>();
|
var inputModel = context.watch<InputProvider>();
|
||||||
var settingsModel = context.watch<SettingsProvider>();
|
var settingsModel = context.watch<SettingsProvider>();
|
||||||
|
var tasksModel = context.watch<TasksProvider>();
|
||||||
return Column(
|
return Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
|
@ -29,7 +31,10 @@ class RelapseForm extends StatelessWidget {
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
height: 80,
|
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:flutter/material.dart';
|
||||||
import 'package:provider/provider.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/elevated_card.dart';
|
||||||
import 'package:smoke_cess_app/widgets/slider.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/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 'package:smoke_cess_app/widgets/timepicker.dart';
|
||||||
|
|
||||||
import '../providers/input_provider.dart';
|
import '../providers/input_provider.dart';
|
||||||
|
import '../services/pages_service.dart';
|
||||||
|
|
||||||
class SleepForm extends StatelessWidget {
|
class SleepForm extends StatelessWidget {
|
||||||
const SleepForm({Key? key}) : super(key: key);
|
const SleepForm({Key? key}) : super(key: key);
|
||||||
|
@ -14,6 +16,7 @@ class SleepForm extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
InputProvider inputModel = context.watch<InputProvider>();
|
InputProvider inputModel = context.watch<InputProvider>();
|
||||||
|
TasksProvider tasksModel = context.watch<TasksProvider>();
|
||||||
String wokeUpKey = 'wokeUpAt';
|
String wokeUpKey = 'wokeUpAt';
|
||||||
String sleptKey = 'sleptAt';
|
String sleptKey = 'sleptAt';
|
||||||
|
|
||||||
|
@ -44,6 +47,7 @@ class SleepForm extends StatelessWidget {
|
||||||
),
|
),
|
||||||
SubmitFormButton(
|
SubmitFormButton(
|
||||||
submitCallback: () => inputModel.saveSleep(wokeUpKey, sleptKey),
|
submitCallback: () => inputModel.saveSleep(wokeUpKey, sleptKey),
|
||||||
|
updateTasks: () => tasksModel.setTaksDone(Pages.mood),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
|
@ -3,7 +3,9 @@ import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class SubmitFormButton extends StatelessWidget {
|
class SubmitFormButton extends StatelessWidget {
|
||||||
final Future<int> Function() submitCallback;
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
@ -12,19 +14,22 @@ class SubmitFormButton extends StatelessWidget {
|
||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
int success = await submitCallback();
|
int success = await submitCallback();
|
||||||
success != 0
|
if (success != 0) {
|
||||||
? AwesomeDialog(
|
AwesomeDialog(
|
||||||
context: context,
|
context: context,
|
||||||
dialogType: DialogType.success,
|
dialogType: DialogType.success,
|
||||||
title: 'Gespeichert',
|
title: 'Gespeichert',
|
||||||
desc: 'Der Eintrag wurde erfolgreich gespeichert',
|
desc: 'Der Eintrag wurde erfolgreich gespeichert',
|
||||||
).show()
|
).show();
|
||||||
: AwesomeDialog(
|
updateTasks();
|
||||||
|
} else {
|
||||||
|
AwesomeDialog(
|
||||||
context: context,
|
context: context,
|
||||||
dialogType: DialogType.error,
|
dialogType: DialogType.error,
|
||||||
title: 'Fehler',
|
title: 'Fehler',
|
||||||
desc: 'Der Eintrag konnte nicht gespeichert werden',
|
desc: 'Der Eintrag konnte nicht gespeichert werden',
|
||||||
).show();
|
).show();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
child: const Text('Speichern'),
|
child: const Text('Speichern'),
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in New Issue