From 566ac1f641a3ec656ba74f38a53a35cdcaa0b4fb Mon Sep 17 00:00:00 2001 From: Username * Date: Sun, 9 Jun 2024 18:38:47 +0100 Subject: [PATCH] the illusion of a faster database --- .../subject_management/subject_screen.dart | 56 +++++++++---------- 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/lib/components/subject_management/subject_screen.dart b/lib/components/subject_management/subject_screen.dart index c51c32b..0c5b0cf 100644 --- a/lib/components/subject_management/subject_screen.dart +++ b/lib/components/subject_management/subject_screen.dart @@ -171,14 +171,15 @@ class SubjectScreen extends HookConsumerWidget { backgroundColor: Theme.of(context).colorScheme.error, foregroundColor: Theme.of(context).colorScheme.errorContainer, ), - onPressed: () { - subjectNotifier.deleteSubject(newSubject); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: const Text('subject_deleted_snackbar').tr(), - ), - ); - Navigator.pop(context); + onPressed: () async { + await subjectNotifier.deleteSubject(newSubject).then((r) { + Navigator.pop(context); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: const Text('subject_deleted_snackbar').tr(), + ), + ); + }); }, child: const Text("delete").tr(), ), @@ -192,34 +193,29 @@ class SubjectScreen extends HookConsumerWidget { foregroundColor: Theme.of(context).colorScheme.secondaryContainer, ), - onPressed: () { + onPressed: () async { if (!formKey.currentState!.validate()) { return; } + if (isOccupied && multipleOccupied) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: const Text('time_slots_occupied_error').tr(), + ), + ); + return; + } if (isSubjectNull) { - if (isOccupied && multipleOccupied) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: const Text('time_slots_occupied_error').tr(), - ), - ); - return; - } - subjectNotifier.addSubject(newSubject.toCompanion(true)); - Navigator.pop(context, label.value); + await subjectNotifier + .addSubject(newSubject.toCompanion(true)) + .then( + (r) => Navigator.pop(context, label.value), + ); } if (!isSubjectNull) { - if (isOccupiedExceptSelf && multipleOccupied) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - // I don't know how to say the error in french so I translated it :P - content: const Text('time_slots_occupied_error').tr(), - ), - ); - return; - } - subjectNotifier.updateSubject(newSubject); - Navigator.pop(context, label.value); + await subjectNotifier.updateSubject(newSubject).then( + (r) => Navigator.pop(context, label.value), + ); } }, child: Text(isSubjectNull ? "create".tr() : "save".tr()),