onViewFocusChange property

ViewFocusChangeCallback? get onViewFocusChange

A callback invoked immediately after the focus is transitioned across FlutterViews.

When the platform moves the focus from one FlutterView to another, this callback is invoked indicating the new view that has focus and the direction in which focus was received. For example, if focus is moved to the FlutterView with ID 2 in the forward direction (could be the result of pressing tab) the callback receives a ViewFocusEvent with ViewFocusState.focused and ViewFocusDirection.forward.

Typically, receivers of this event respond by moving the focus to the first focusable widget inside the FlutterView with ID 2. If a view receives focus in the backward direction (could be the result of pressing shift + tab), typically the last focusable widget inside that view is focused.

The platform may remove focus from a FlutterView. For example, on the web, the browser can move focus to another element, or to the browser's built-in UI. On desktop, the operating system can switch to another window (e.g. using Alt + Tab on Windows). In scenarios like these, onViewFocusChange will be invoked with ViewFocusState.unfocused and ViewFocusDirection.undefined.

Receivers typically respond to this event by removing all focus indications from the app.

Apps can also programmatically request to move the focus to a desired FlutterView by calling requestViewFocusChange.

The callback is invoked in the same zone in which the callback was set.

See also:

Implementation

ViewFocusChangeCallback? get onViewFocusChange => _onViewFocusChange;
set onViewFocusChange (ViewFocusChangeCallback? callback)

Implementation

set onViewFocusChange(ViewFocusChangeCallback? callback) {
  _onViewFocusChange = callback;
  _onViewFocusChangeZone = Zone.current;
}