PopBehavior class

Configuration for how a Navigator handles pop requests via keyboard.

By default, pressing Escape will pop the current route (if the stack has more than one route). Backspace popping is disabled by default.

Navigator(
  popBehavior: PopBehavior(
    escapeEnabled: true,
    backspaceEnabled: false,
    customPopKey: 'q',
  ),
  home: HomeScreen(),
)

Constructors

PopBehavior({bool escapeEnabled = true, bool backspaceEnabled = false, String? customPopKey, bool canPop(Route)?, Future<bool> onPopInvoked(Route)?})
Creates a pop behavior configuration.
const

Properties

backspaceEnabled bool
Whether pressing Backspace triggers a pop.
final
canPop bool Function(Route)?
Optional callback to determine if popping is allowed for the current route. If null, the navigator's default canPop logic is used.
final
customPopKey String?
An optional custom character key that triggers a pop (e.g., 'q').
final
escapeEnabled bool
Whether pressing Escape triggers a pop.
final
hashCode int
The hash code for this object.
no setterinherited
onPopInvoked Future<bool> Function(Route)?
Optional async callback invoked before popping, allowing confirmation dialogs (e.g., "Discard unsaved changes?"). Return true to allow the pop, false to prevent it.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
shouldPop(KeyMsg msg) bool
Returns true if the given msg should trigger a pop action based on this configuration.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Constants

defaultBehavior → const PopBehavior
Default behavior: only Escape pops.
strict → const PopBehavior
Strict behavior: no keyboard-triggered pops.