Skip to content

FocusScope

A boundary for focus memory and optional focus trapping.

Learn more: Focus management

Import: package:fleury/fleury.dart, or package:fleury/fleury_core.dart in browser code.

// Keep focus inside a custom overlay: Tab, clicks, and focus requests
// can't move it out.
FocusScope(
trapFocus: true,
// Stop unmatched keys from reaching the app behind it too.
child: KeyBindings(modal: true, bindings: const [], child: child),
)

Every scope remembers its most recently focused descendant. With trapFocus enabled, programmatic focus, pointer focus, and traversal are confined to this subtree. Key events may still propagate to ancestors; use KeyBindings(modal: true) when unmatched keys must also stop here.

Navigator routes install their own scope and traversal policy. Presented dialogs enable trapFocus and a key-binding boundary automatically.

ParameterTypeDefaultDescription
trapFocus:boolfalseWhether focus must stay inside this scope. More
child:WidgetrequiredThe subtree that shares this focus scope.
  • trapFocus: When true, Tab and arrow traversal, pointer focus, and direct FocusNode.requestFocus calls cannot move focus outside this subtree. This does not stop key events from propagating to ancestor handlers.

FocusScope is defined in packages/fleury/lib/src/widgets/focus.dart.

Category: Input handling & focus · All widgets