From 6ebb260cb3e12ba556b3eb039a5085cf0cddd22d Mon Sep 17 00:00:00 2001 From: Michael Aziz Date: Sat, 24 Jan 2026 11:39:43 +0200 Subject: [PATCH] [FIX] Dialog sismissing helpers --- lib/src/dialog/dialog_helper.astromic.dart | 36 +++++++++++++------ .../src/models/configuration.model.dart | 5 ++- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/lib/src/dialog/dialog_helper.astromic.dart b/lib/src/dialog/dialog_helper.astromic.dart index c2c0ed8..5f85dd7 100644 --- a/lib/src/dialog/dialog_helper.astromic.dart +++ b/lib/src/dialog/dialog_helper.astromic.dart @@ -10,14 +10,27 @@ class AstromicDialogHelper { Widget? stackedCloseWidget, AstromicDialogConfiguration configuration = const AstromicDialogConfiguration(), AstromicDialogStyle style = const AstromicDialogStyle(), - void Function(T?)? onClose, + Future Function()? onWillDismess, }) async { - // - return await showDialog( - context: context, - useSafeArea: configuration.safeAreaAware, - builder: (_) { - return Dialog( + final result = await showDialog( + context: context, + useSafeArea: configuration.safeAreaAware, + barrierDismissible: configuration.barrierDismissible, + builder: (modalContext) { + return PopScope( + canPop: false, // We set this to false to manually control the pop + onPopInvokedWithResult: (didPop, result) async { + if (didPop) return; + + // Check your custom logic + final shouldPop = onWillDismess != null ? await onWillDismess() : true; + + if (shouldPop) { + // ignore: use_build_context_synchronously + Navigator.of(modalContext).pop(); + } + }, + child: Dialog( backgroundColor: Colors.transparent, insetPadding: style.margin?.resolve(style.textDirection) ?? const EdgeInsets.symmetric(horizontal: 40, vertical: 24), child: Stack( @@ -42,8 +55,11 @@ class AstromicDialogHelper { ), ], ), - ); - }); - // + ), + ); + }, + ); + + return result; } } diff --git a/lib/src/dialog/src/models/configuration.model.dart b/lib/src/dialog/src/models/configuration.model.dart index 14919cd..99f115e 100644 --- a/lib/src/dialog/src/models/configuration.model.dart +++ b/lib/src/dialog/src/models/configuration.model.dart @@ -1,16 +1,19 @@ class AstromicDialogConfiguration { const AstromicDialogConfiguration({ this.safeAreaAware = true, + this.barrierDismissible = true, }); final bool safeAreaAware; + final bool barrierDismissible; AstromicDialogConfiguration copyWith({ - bool? isCentered, bool? safeAreaAware, + bool? barrierDismissible, }) { return AstromicDialogConfiguration( safeAreaAware: safeAreaAware ?? this.safeAreaAware, + barrierDismissible: barrierDismissible ?? this.barrierDismissible, ); } }