saveButtonHandler method
- BuildContext context,
- WidgetRef ref
Handles the save button press.
Implementation
Future<void> saveButtonHandler(BuildContext context, WidgetRef ref) async {
if (Form.of(context).validate() != true) {
// Show a snackbar if the form is not valid.
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(t.generics.fillAllFields)),
);
return;
}
Form.of(context).save();
FocusScope.of(context).unfocus();
// Ask the user if they want to continue without a banner.
confirmBanner(ref, context).then((shouldContinue) async {
if (!shouldContinue) return;
ref.read(isInAsyncProvider.notifier).setTrue();
// Upload the banner if needed.
await ref.read(createActivityProvider.notifier).uploadBannerIfNeeded();
// Save the activity to the database.
ref.read(createActivityProvider.notifier).saveActivity().then((result) {
ref.read(isInAsyncProvider.notifier).setFalse();
if (result == CreateActivityResult.error) {
// Show a snackbar if there was an error.
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(t.error.unknown),
),
);
} else {
// Leave the page if the activity was saved successfully.
context.pop();
}
});
});
}