[FIX] Dialog sismissing helpers
This commit is contained in:
@@ -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,
|
barrierDismissible: configuration.barrierDismissible,
|
||||||
builder: (_) {
|
builder: (modalContext) {
|
||||||
return Dialog(
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user