aboutsummaryrefslogtreecommitdiff
path: root/lib/widgets/common/behaviour/pop/scope.dart
diff options
context:
space:
mode:
authormirror <mirror@localhost>2026-11-22 08:41:00 +0900
committermirror <mirror@localhost>2026-11-22 08:41:00 +0900
commit449d8b74bd6d9dae98a07254cdfad677b920e7b0 (patch)
treec131c3528c4d517f56e19b854a7453fedb097d40 /lib/widgets/common/behaviour/pop/scope.dart
downloadaves-src-master.tar.gz
aves-src-master.zip
snapshot of aves v1.13.12 (secrets removed: android/app/google-services.json)HEADv1.13.12master
Diffstat (limited to 'lib/widgets/common/behaviour/pop/scope.dart')
-rw-r--r--lib/widgets/common/behaviour/pop/scope.dart54
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/widgets/common/behaviour/pop/scope.dart b/lib/widgets/common/behaviour/pop/scope.dart
new file mode 100644
index 0000000..ff750b9
--- /dev/null
+++ b/lib/widgets/common/behaviour/pop/scope.dart
@@ -0,0 +1,54 @@
+import 'package:collection/collection.dart';
+import 'package:flutter/widgets.dart';
+
+// this widget combines multiple pop handlers with a guaranteed order
+class AvesPopScope extends StatelessWidget {
+ final List<PopHandler> handlers;
+ final Widget child;
+
+ const AvesPopScope({
+ super.key,
+ required this.handlers,
+ required this.child,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ final blocker = handlers.firstWhereOrNull((v) => !v.canPop(context));
+ return PopScope(
+ canPop: blocker == null,
+ onPopInvokedWithResult: (didPop, result) {
+ if (!didPop) {
+ blocker?.onPopBlocked(context);
+ }
+ },
+ child: child,
+ );
+ }
+}
+
+abstract class PopHandler {
+ bool canPop(BuildContext context);
+
+ void onPopBlocked(BuildContext context);
+}
+
+class APopHandler implements PopHandler {
+ final bool Function(BuildContext context) _canPop;
+ final void Function(BuildContext context) _onPopBlocked;
+
+ APopHandler({
+ required bool Function(BuildContext context) canPop,
+ required void Function(BuildContext context) onPopBlocked,
+ }) : _canPop = canPop,
+ _onPopBlocked = onPopBlocked;
+
+ @override
+ bool canPop(BuildContext context) => _canPop(context);
+
+ @override
+ void onPopBlocked(BuildContext context) => _onPopBlocked(context);
+}
+
+@immutable
+class PopExitNotification extends Notification {}