Skip to content

Commit

Permalink
add ontap for snack
Browse files Browse the repository at this point in the history
  • Loading branch information
shirne committed Oct 23, 2023
1 parent d8ec4d8 commit 1e10232
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions lib/src/my_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ class MyDialog {
/// A wrapper of [ShirneDialog.snack]
static EntryController snack(
dynamic message, {
VoidCallback? onTap,
Widget? action,
Duration? duration,
Alignment? align,
Expand All @@ -372,6 +373,7 @@ class MyDialog {
_checkInstance();
return _instance!.snack(
message,
onTap: onTap,
action: action,
duration: duration,
align: align,
Expand Down Expand Up @@ -895,6 +897,7 @@ class ShirneDialog {
EntryController snack(
/// [SnackWidget] Or [String]
dynamic message, {
VoidCallback? onTap,
Widget? action,
Duration? duration,
Alignment? align,
Expand All @@ -905,14 +908,26 @@ class ShirneDialog {
final snackStyle = (style ?? theme.snackStyle)?.bottomIfNoAlign(
isAnimate: true,
);
final controller = overlayModal(
message is Widget
? message
: SnackWidget(
message,
action: action,
maxWidth: width,
style: snackStyle,
final child = message is Widget
? message
: SnackWidget(
message,
action: action,
maxWidth: width,
style: snackStyle,
);
EntryController? controller;
controller = overlayModal(
onTap == null
? child
: GestureDetector(
onTap: () {
onTap.call();
if (!controller!.isClosed) {
controller.close();
}
},
child: child,
),
animate: snackStyle?.enterAnimation ??
AnimationConfig.fadeIn.copyWith(
Expand All @@ -923,7 +938,7 @@ class ShirneDialog {
);

Future.delayed(duration ?? const Duration(seconds: 3)).then((value) {
if (!controller.isClosed) {
if (!controller!.isClosed) {
controller.close();
}
});
Expand Down

0 comments on commit 1e10232

Please sign in to comment.