fix: simplify DefaultConfirmationDialog usage by handling the possible null value internally

This commit is contained in:
Bart Ribbers 2024-07-18 14:28:23 +02:00 committed by Freek van de Ven
parent bb337a4084
commit 226c90943a
4 changed files with 23 additions and 17 deletions

View file

@ -198,7 +198,7 @@ typedef TimePickerBuilder = Future<TimeOfDay?> Function(
///
/// The function should return a [Future] that resolves to `true` if the user
/// confirms.
typedef ConfirmationDialogBuilder = Future<bool?> Function(
typedef ConfirmationDialogBuilder = Future<bool> Function(
BuildContext context, {
required String title,
required String description,

View file

@ -99,14 +99,13 @@ class _AvailabilitiesModificationScreenState
Future<void> onClickSave() async {
// TODO(Joey): The name confirmationDialogBuilder does not represent the
// expected implementation.
var confirmed = await options.confirmationDialogBuilder(
var isConfirmed = await options.confirmationDialogBuilder(
context,
title: translations.availabilityDialogConfirmTitle,
description: translations.availabilityDialogConfirmDescription,
);
// TODO(Joey): We should make the interface of the dialog function return
// a non nullable bool. Now we are implicitly setting default behaviour
if (confirmed ?? false) {
if (isConfirmed) {
await onSave();
}
}

View file

@ -111,12 +111,12 @@ class _AvailabilityOverviewState extends State<AvailabilityOverview> {
}
Future<void> onClearButtonClicked() async {
var confirmed = await options.confirmationDialogBuilder(
var isConfirmed = await options.confirmationDialogBuilder(
context,
title: translations.clearAvailabilityConfirmTitle,
description: translations.clearAvailabilityConfirmDescription,
);
if (confirmed ?? false) {
if (isConfirmed) {
await service
.clearAvailabilities(selectedAvailabilities.getAvailabilities());
setState(() {

View file

@ -13,19 +13,26 @@ class DefaultConfirmationDialog extends StatelessWidget {
});
/// Shows a confirmation dialog with a title and a description
static Future<bool?> builder(
static Future<bool> builder(
BuildContext context, {
required String title,
required String description,
}) =>
showModalBottomSheet(
context: context,
shape: const RoundedRectangleBorder(),
builder: (context) => DefaultConfirmationDialog(
title: title,
description: description,
),
);
}) async {
var isConfirmed = await showModalBottomSheet<bool>(
context: context,
shape: const RoundedRectangleBorder(),
builder: (context) => DefaultConfirmationDialog(
title: title,
description: description,
),
);
if (isConfirmed == null) {
return false;
}
return isConfirmed;
}
/// The title shown in the dialog
final String title;