Skip to content

Commit 7277c51

Browse files
authored
Merge pull request #22 from DutchCodingCompany/fix/closing_dialogs
✨ Added automatic closing of native dialog
2 parents ddeedab + 589f00e commit 7277c51

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## 0.0.13
4+
* added automatic closing of native dialog.
5+
36
## 0.0.12
47
* Updated dependencies
58
* Added test_util: catch presentation event helper, DeviceSizes

lib/ui/native_dialog.dart

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,17 @@ void showNativeDialog(
2525
showCupertinoDialog<void>(
2626
context: context,
2727
builder:
28-
(context) => CupertinoAlertDialog(
28+
(dialogContext) => CupertinoAlertDialog(
2929
title: Text(title),
3030
content: Text(content),
3131
actions:
3232
actions
3333
.map(
3434
(action) => CupertinoDialogAction(
35-
onPressed: action.onTap,
35+
onPressed: () {
36+
action.onTap();
37+
Navigator.of(dialogContext).pop();
38+
},
3639
isDestructiveAction: action.isDestructiveAction,
3740
child: Text(action.text),
3841
),
@@ -44,16 +47,27 @@ void showNativeDialog(
4447
showDialog<void>(
4548
context: context,
4649
builder:
47-
(context) => AlertDialog(
50+
(dialogContext) => AlertDialog(
4851
title: Text(title),
4952
content: Text(content),
50-
actions: actions.map((action) => TextButton(onPressed: action.onTap, child: Text(action.text))).toList(),
53+
actions:
54+
actions
55+
.map(
56+
(action) => TextButton(
57+
onPressed: () {
58+
action.onTap();
59+
Navigator.of(dialogContext).pop();
60+
},
61+
child: Text(action.text),
62+
),
63+
)
64+
.toList(),
5165
),
5266
);
5367
}
5468
}
5569

56-
/// A dialog action which is used to show the actions of a native dialog.
70+
/// A dialog action which is used to show the actions of a native dialog. Tapping a action will also close the dialog.
5771
class DialogAction {
5872
/// Creates a [DialogAction].
5973
const DialogAction({required this.text, required this.onTap, this.isDestructiveAction = false});

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: dcc_toolkit
22
description: "Internal toolkit package used by the DCC team."
3-
version: 0.0.12
3+
version: 0.0.13
44
homepage: https://dutchcodingcompany.com
55
repository: https://github.com/DutchCodingCompany/dcc_toolkit
66

0 commit comments

Comments
 (0)