PopScope
Guards the route it sits in against a user’s request to go back.
Learn more: Navigation & dialogs
Import: package:fleury/fleury.dart, or package:fleury/fleury_core.dart in browser code.
PopScope( canPop: !hasUnsavedChanges, onBlocked: () => setState(() => status = 'Save or discard first'), child: editor,)Details
Section titled “Details”A back request is an Escape the screen doesn’t handle itself, a call to
NavigatorState.maybePop (a Back button or command), or the route’s
semantic close or dismiss action. While canPop is false, such a request
leaves the route open and calls onBlocked instead — the place to confirm
“discard changes?”. NavigatorState.pop (context.pop()) is NOT
intercepted, so the screen can still close itself once the user confirms;
nor are the other stack changes, such as NavigatorState.popUntil and
NavigatorState.pushReplacement.
A PopScope guards the route of its nearest Navigator, and only the top
route’s guards are consulted, so a guarded screen beneath a dialog doesn’t
stop the dialog from closing. Multiple PopScopes in one route compose: any
with canPop == false blocks, and each that blocks has its onBlocked
called.
At the root, where there is nothing to pop, an Escape passes on to key
bindings outside the navigator. A PopScope there with canPop false
consumes that Escape and calls onBlocked, so a screen can confirm before
an app exit bound to Escape. It never intercepts Ctrl+C.
Constructors
Section titled “Constructors”PopScope()
Section titled “PopScope()”| Parameter | Type | Default | Description |
|---|---|---|---|
child: | Widget | required | The guarded content, typically the route’s screen. PopScope builds it unchanged. |
canPop: | bool | true | Whether a back request may pop this route. When false the attempt is vetoed and onBlocked fires. More |
onBlocked: | VoidCallback? | — | Called when a back request was vetoed (because canPop was false). More |
canPop: Read at each attempt, so rebuilding with a new value (for example when unsaved changes appear) applies to the next one.onBlocked: Runs during the attempt, once per vetoed attempt, and never forNavigatorState.pop.
Source
Section titled “Source”PopScope is defined in packages/fleury/lib/src/widgets/navigator.dart.
Category: Navigation & overlays · All widgets