[FIX] Dialog sismissing helpers
This commit is contained in:
@@ -10,14 +10,27 @@ class AstromicDialogHelper {
|
||||
Widget? stackedCloseWidget,
|
||||
AstromicDialogConfiguration configuration = const AstromicDialogConfiguration(),
|
||||
AstromicDialogStyle style = const AstromicDialogStyle(),
|
||||
void Function(T?)? onClose,
|
||||
Future<bool> Function()? onWillDismess,
|
||||
}) async {
|
||||
//
|
||||
return await showDialog<T>(
|
||||
context: context,
|
||||
useSafeArea: configuration.safeAreaAware,
|
||||
builder: (_) {
|
||||
return Dialog(
|
||||
final result = await showDialog<T>(
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user