2023-02-27 20:02:15 +01:00
|
|
|
import 'package:awesome_dialog/awesome_dialog.dart';
|
2023-02-15 23:28:19 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2023-03-03 12:51:48 +01:00
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:smoke_cess_app/providers/page_provider.dart';
|
2023-03-06 15:46:40 +01:00
|
|
|
import 'package:smoke_cess_app/widgets/buttons/round_button_widget.dart';
|
2023-02-15 23:28:19 +01:00
|
|
|
|
|
|
|
class SubmitFormButton extends StatelessWidget {
|
2023-02-27 20:02:15 +01:00
|
|
|
final Future<int> Function() submitCallback;
|
2023-03-02 20:16:46 +01:00
|
|
|
final void Function() updateTasks;
|
|
|
|
const SubmitFormButton(
|
|
|
|
{super.key, required this.submitCallback, required this.updateTasks});
|
2023-02-15 23:28:19 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-03-03 12:51:48 +01:00
|
|
|
PageProvider pageProvider = context.watch<PageProvider>();
|
2023-02-15 23:28:19 +01:00
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 16.0),
|
2023-03-06 15:46:40 +01:00
|
|
|
child: RoundIconButton(
|
2023-02-27 20:02:15 +01:00
|
|
|
onPressed: () async {
|
|
|
|
int success = await submitCallback();
|
2023-03-04 10:29:35 +01:00
|
|
|
if (context.mounted) {
|
|
|
|
if (success != 0) {
|
|
|
|
await AwesomeDialog(
|
|
|
|
context: context,
|
|
|
|
dialogType: DialogType.success,
|
|
|
|
title: 'Gespeichert',
|
|
|
|
desc: 'Der Eintrag wurde erfolgreich gespeichert',
|
|
|
|
).show();
|
|
|
|
updateTasks();
|
|
|
|
pageProvider.swap();
|
|
|
|
} else {
|
|
|
|
await AwesomeDialog(
|
|
|
|
context: context,
|
|
|
|
dialogType: DialogType.error,
|
|
|
|
title: 'Fehler',
|
|
|
|
desc: 'Der Eintrag konnte nicht gespeichert werden',
|
|
|
|
).show();
|
|
|
|
}
|
2023-03-02 20:16:46 +01:00
|
|
|
}
|
2023-02-27 20:02:15 +01:00
|
|
|
},
|
2023-03-06 15:46:40 +01:00
|
|
|
iconData: Icons.check_outlined,
|
2023-02-15 23:28:19 +01:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|