From 589f00e7b8fc0ed7e6b25c6274602d887808af57 Mon Sep 17 00:00:00 2001 From: Job Guldemeester Date: Fri, 18 Apr 2025 14:25:24 +0200 Subject: [PATCH] :sparkles: Added automatic closing of native dialog --- CHANGELOG.md | 3 +++ lib/ui/native_dialog.dart | 24 +++++++++++++++++++----- pubspec.yaml | 2 +- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f9cbba7..3ad7535 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## 0.0.13 +* added automatic closing of native dialog. + ## 0.0.12 * Updated dependencies * Added test_util: catch presentation event helper, DeviceSizes diff --git a/lib/ui/native_dialog.dart b/lib/ui/native_dialog.dart index 7bc87ba..d1c79c2 100644 --- a/lib/ui/native_dialog.dart +++ b/lib/ui/native_dialog.dart @@ -25,14 +25,17 @@ void showNativeDialog( showCupertinoDialog( context: context, builder: - (context) => CupertinoAlertDialog( + (dialogContext) => CupertinoAlertDialog( title: Text(title), content: Text(content), actions: actions .map( (action) => CupertinoDialogAction( - onPressed: action.onTap, + onPressed: () { + action.onTap(); + Navigator.of(dialogContext).pop(); + }, isDestructiveAction: action.isDestructiveAction, child: Text(action.text), ), @@ -44,16 +47,27 @@ void showNativeDialog( showDialog( context: context, builder: - (context) => AlertDialog( + (dialogContext) => AlertDialog( title: Text(title), content: Text(content), - actions: actions.map((action) => TextButton(onPressed: action.onTap, child: Text(action.text))).toList(), + actions: + actions + .map( + (action) => TextButton( + onPressed: () { + action.onTap(); + Navigator.of(dialogContext).pop(); + }, + child: Text(action.text), + ), + ) + .toList(), ), ); } } -/// A dialog action which is used to show the actions of a native dialog. +/// A dialog action which is used to show the actions of a native dialog. Tapping a action will also close the dialog. class DialogAction { /// Creates a [DialogAction]. const DialogAction({required this.text, required this.onTap, this.isDestructiveAction = false}); diff --git a/pubspec.yaml b/pubspec.yaml index aeb3e9d..7b3cc9c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: dcc_toolkit description: "Internal toolkit package used by the DCC team." -version: 0.0.12 +version: 0.0.13 homepage: https://dutchcodingcompany.com repository: https://github.com/DutchCodingCompany/dcc_toolkit