mirror of
https://github.com/Iconica-Development/flutter_availability.git
synced 2025-05-19 13:13:44 +02:00
fix: simplify DefaultConfirmationDialog usage by handling the possible null value internally
This commit is contained in:
parent
bb337a4084
commit
226c90943a
4 changed files with 23 additions and 17 deletions
|
@ -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,
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(() {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue