[FIX] Dialog sismissing helpers

This commit is contained in:
2026-01-24 11:39:43 +02:00
parent 2b3d758987
commit 6ebb260cb3
2 changed files with 30 additions and 11 deletions

View File

@@ -10,14 +10,27 @@ class AstromicDialogHelper {
Widget? stackedCloseWidget, Widget? stackedCloseWidget,
AstromicDialogConfiguration configuration = const AstromicDialogConfiguration(), AstromicDialogConfiguration configuration = const AstromicDialogConfiguration(),
AstromicDialogStyle style = const AstromicDialogStyle(), AstromicDialogStyle style = const AstromicDialogStyle(),
void Function(T?)? onClose, Future<bool> Function()? onWillDismess,
}) async { }) async {
// final result = await showDialog<T>(
return await showDialog<T>(
context: context, context: context,
useSafeArea: configuration.safeAreaAware, useSafeArea: configuration.safeAreaAware,
builder: (_) { barrierDismissible: configuration.barrierDismissible,
return Dialog( 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, backgroundColor: Colors.transparent,
insetPadding: style.margin?.resolve(style.textDirection) ?? const EdgeInsets.symmetric(horizontal: 40, vertical: 24), insetPadding: style.margin?.resolve(style.textDirection) ?? const EdgeInsets.symmetric(horizontal: 40, vertical: 24),
child: Stack( child: Stack(
@@ -42,8 +55,11 @@ class AstromicDialogHelper {
), ),
], ],
), ),
),
); );
}); },
// );
return result;
} }
} }

View File

@@ -1,16 +1,19 @@
class AstromicDialogConfiguration { class AstromicDialogConfiguration {
const AstromicDialogConfiguration({ const AstromicDialogConfiguration({
this.safeAreaAware = true, this.safeAreaAware = true,
this.barrierDismissible = true,
}); });
final bool safeAreaAware; final bool safeAreaAware;
final bool barrierDismissible;
AstromicDialogConfiguration copyWith({ AstromicDialogConfiguration copyWith({
bool? isCentered,
bool? safeAreaAware, bool? safeAreaAware,
bool? barrierDismissible,
}) { }) {
return AstromicDialogConfiguration( return AstromicDialogConfiguration(
safeAreaAware: safeAreaAware ?? this.safeAreaAware, safeAreaAware: safeAreaAware ?? this.safeAreaAware,
barrierDismissible: barrierDismissible ?? this.barrierDismissible,
); );
} }
} }