@@ -25,14 +25,17 @@ void showNativeDialog(
25
25
showCupertinoDialog <void >(
26
26
context: context,
27
27
builder:
28
- (context ) => CupertinoAlertDialog (
28
+ (dialogContext ) => CupertinoAlertDialog (
29
29
title: Text (title),
30
30
content: Text (content),
31
31
actions:
32
32
actions
33
33
.map (
34
34
(action) => CupertinoDialogAction (
35
- onPressed: action.onTap,
35
+ onPressed: () {
36
+ action.onTap ();
37
+ Navigator .of (dialogContext).pop ();
38
+ },
36
39
isDestructiveAction: action.isDestructiveAction,
37
40
child: Text (action.text),
38
41
),
@@ -44,16 +47,27 @@ void showNativeDialog(
44
47
showDialog <void >(
45
48
context: context,
46
49
builder:
47
- (context ) => AlertDialog (
50
+ (dialogContext ) => AlertDialog (
48
51
title: Text (title),
49
52
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 (),
51
65
),
52
66
);
53
67
}
54
68
}
55
69
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.
57
71
class DialogAction {
58
72
/// Creates a [DialogAction] .
59
73
const DialogAction ({required this .text, required this .onTap, this .isDestructiveAction = false });
0 commit comments