FocusTrapScope class

Standard "modal focus trap" for an in-tree overlay panel — wraps child (the modal's own content) in a FocusScope that autofocuses as soon as this widget mounts (i.e. exactly when the overlay it belongs to appears, matching this package's "always mounted, panel nullable" convention — NeonDialog.overlaySlot, PauseOverlay), and restores focus to whatever had it right BEFORE this widget mounted, the moment it's removed from the tree again (the overlay closing).

FEAT-82 closes exactly the gap PauseOverlay's own doc comment (FEAT-53) flagged: a bare FocusScope(autofocus: true) grabs focus when a modal appears but has no way to give it back to the right place when the modal's subtree gets torn down — Flutter's own FocusManager just falls back toward the tree root instead, so a keyboard/gamepad player closing a dialog would otherwise lose their place entirely.

Deterministic order: traversal WITHIN child uses Flutter's own default FocusTraversalPolicy (tree/paint order) — this widget adds no custom ordering, since none of the trap/release behavior it exists for depends on child order.

Purely additive for touch-only play: nothing here changes what a tap does; the whole effect is scoped to keyboard/gamepad focus, which a touch-only session never engages with (same guarantee PressableScale's own focus-ring doc comment gives for the same reason).

Inheritance

Constructors

FocusTrapScope({Key? key, required Widget child, bool autofocus = true})
const

Properties

autofocus → bool
final
child → Widget
final
hashCode → int
The hash code for this object.
no setterinherited
key → Key?
Controls how one widget replaces another widget in the tree.
finalinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

createElement() → StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() → State<FocusTrapScope>
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() → List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) → String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String
Returns a one-line detailed description of the object.
inherited
toStringShort() → String
A short, textual description of this widget.
inherited

Operators

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