From 5a48a416b8dfa11b7c22610920982eb31a91cf6a Mon Sep 17 00:00:00 2001 From: xubaolin Date: Wed, 4 Aug 2021 09:25:05 +0800 Subject: [PATCH] Update some Focus docs (#87561) --- packages/flutter/lib/src/widgets/focus_manager.dart | 11 ++++++----- packages/flutter/lib/src/widgets/focus_scope.dart | 13 +++++++------ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/packages/flutter/lib/src/widgets/focus_manager.dart b/packages/flutter/lib/src/widgets/focus_manager.dart index cfd2100d00..d2be6e0b96 100644 --- a/packages/flutter/lib/src/widgets/focus_manager.dart +++ b/packages/flutter/lib/src/widgets/focus_manager.dart @@ -309,11 +309,12 @@ enum UnfocusDisposition { /// The [FocusManager] receives key events from [RawKeyboard] and /// [HardwareKeyboard] and will pass them to the focused nodes. It starts with /// the node with the primary focus, and will call the [onKey] or [onKeyEvent] -/// callback for that node. If the callback returns false, indicating that it did -/// not handle the event, the [FocusManager] will move to the parent of that node -/// and call its [onKey] or [onKeyEvent]. If that [onKey] or [onKeyEvent] returns -/// true, then it will stop propagating the event. If it reaches the root -/// [FocusScopeNode], [FocusManager.rootScope], the event is discarded. +/// callback for that node. If the callback returns [KeyEventResult.ignored], +/// indicating that it did not handle the event, the [FocusManager] will move +/// to the parent of that node and call its [onKey] or [onKeyEvent]. If that +/// [onKey] or [onKeyEvent] returns [KeyEventResult.handled], then it will stop +/// propagating the event. If it reaches the root [FocusScopeNode], +/// [FocusManager.rootScope], the event is discarded. /// {@endtemplate} /// /// ## Focus Traversal diff --git a/packages/flutter/lib/src/widgets/focus_scope.dart b/packages/flutter/lib/src/widgets/focus_scope.dart index 673429a4b1..9e42c2c738 100644 --- a/packages/flutter/lib/src/widgets/focus_scope.dart +++ b/packages/flutter/lib/src/widgets/focus_scope.dart @@ -16,7 +16,7 @@ import 'inherited_notifier.dart'; /// /// For keyboard events, [onKey] is called if [FocusNode.hasFocus] is true for /// this widget's [focusNode], unless a focused descendant's [onKey] callback -/// returns true when called. +/// returns [KeyEventResult.handled] when called. /// /// This widget does not provide any visual indication that the focus has /// changed. Any desired visual changes should be made when [onFocusChange] is @@ -316,9 +316,9 @@ class Focus extends StatefulWidget { /// focus. /// /// Key events are first given to the [FocusNode] that has primary focus, and - /// if its [onKeyEvent] method return false, then they are given to each - /// ancestor node up the focus hierarchy in turn. If an event reaches the root - /// of the hierarchy, it is discarded. + /// if its [onKeyEvent] method returns [KeyEventResult.ignored], then they are + /// given to each ancestor node up the focus hierarchy in turn. If an event + /// reaches the root of the hierarchy, it is discarded. /// /// This is not the way to get text input in the manner of a text field: it /// leaves out support for input method editors, and doesn't support soft @@ -742,8 +742,9 @@ class _FocusState extends State { /// The [onKey] argument allows specification of a key event handler that is /// invoked when this node or one of its children has focus. Keys are handed to /// the primary focused widget first, and then they propagate through the -/// ancestors of that node, stopping if one of them returns true from [onKey], -/// indicating that it has handled the event. +/// ancestors of that node, stopping if one of them returns +/// [KeyEventResult.handled] from [onKey], indicating that it has handled the +/// event. /// /// Managing a [FocusScopeNode] means managing its lifecycle, listening for /// changes in focus, and re-parenting it when needed to keep the focus