Skip to content

Commit

Permalink
Fix some Focus related documentation typos (#118576)
Browse files Browse the repository at this point in the history
* Fix focus area documentation typos

* Restore intentional spaces that illustrate bigger buttons
  • Loading branch information
bleroux committed Jan 18, 2023
1 parent f989d55 commit 0eaa83a
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 82 deletions.
7 changes: 4 additions & 3 deletions packages/flutter/lib/src/widgets/actions.dart
Expand Up @@ -954,7 +954,7 @@ class Actions extends StatefulWidget {
final Action<T>? result = _castAction(actions, intent: intent);
if (result != null && result.isEnabled(intent)) {
// Invoke the action we found using the relevant dispatcher from the Actions
// Element we found.
// element we found.
returnValue = _findDispatcher(element).invokeAction(result, intent, context);
}
return result != null;
Expand Down Expand Up @@ -1478,7 +1478,8 @@ class ActivateIntent extends Intent {
/// * [WidgetsApp.shortcuts], which defines the shortcuts to use in an
/// application (and defaults to [WidgetsApp.defaultShortcuts]).
class ButtonActivateIntent extends Intent {
/// Creates an intent that the currently focused control, if it's a button.
/// Creates an intent that activates the currently focused control,
/// if it's a button.
const ButtonActivateIntent();
}

Expand Down Expand Up @@ -1581,7 +1582,7 @@ mixin _OverridableActionMixin<T extends Intent> on Action<T> {
bool debugAssertConsumeKeyMutuallyRecursive = false;

// The default action to invoke if an enabled override Action can't be found
// using [lookupContext];
// using [lookupContext].
Action<T> get defaultAction;

// The [BuildContext] used to find the override of this [Action].
Expand Down
14 changes: 7 additions & 7 deletions packages/flutter/lib/src/widgets/focus_manager.dart
Expand Up @@ -110,7 +110,7 @@ class _Autofocus {
// The widget tree is responsible for calling reparent/detach on attached
// nodes to keep their parent/manager information up-to-date, so here we can
// safely check if the scope/node involved in each autofocus request is
// still attached, and discard the ones are no longer attached to the
// still attached, and discard the ones which are no longer attached to the
// original manager.
void applyIfValid(FocusManager manager) {
final bool shouldApply = (scope.parent != null || identical(scope, manager.rootScope))
Expand All @@ -128,8 +128,8 @@ class _Autofocus {

/// An attachment point for a [FocusNode].
///
/// Using a [FocusAttachment] is rarely needed, unless you are building
/// something akin to the [Focus] or [FocusScope] widgets from scratch.
/// Using a [FocusAttachment] is rarely needed, unless building something
/// akin to the [Focus] or [FocusScope] widgets from scratch.
///
/// Once created, a [FocusNode] must be attached to the widget tree by its
/// _host_ [StatefulWidget] via a [FocusAttachment] object. [FocusAttachment]s
Expand Down Expand Up @@ -261,8 +261,8 @@ enum UnfocusDisposition {
///
/// _Please see the [Focus] and [FocusScope] widgets, which are utility widgets
/// that manage their own [FocusNode]s and [FocusScopeNode]s, respectively. If
/// they aren't appropriate, [FocusNode]s can be managed directly, but doing
/// this yourself is rare._
/// they aren't appropriate, [FocusNode]s can be managed directly, but doing this
/// is rare._
///
/// [FocusNode]s are persistent objects that form a _focus tree_ that is a
/// representation of the widgets in the hierarchy that are interested in focus.
Expand Down Expand Up @@ -1405,8 +1405,8 @@ enum FocusHighlightStrategy {
/// The focus manager is responsible for tracking which [FocusNode] has the
/// primary input focus (the [primaryFocus]), holding the [FocusScopeNode] that
/// is the root of the focus tree (the [rootScope]), and what the current
/// [highlightMode] is. It also distributes key events from [RawKeyboard] to the
/// nodes in the focus tree.
/// [highlightMode] is. It also distributes key events from [KeyEventManager]
/// to the nodes in the focus tree.
///
/// The singleton [FocusManager] instance is held by the [WidgetsBinding] as
/// [WidgetsBinding.focusManager], and can be conveniently accessed using the
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/widgets/focus_scope.dart
Expand Up @@ -195,7 +195,7 @@ class Focus extends StatefulWidget {
/// {@endtemplate}
///
/// A non-null [focusNode] must be supplied if using the
/// [Focus.withExternalFocusNode] constructor is used.
/// [Focus.withExternalFocusNode] constructor.
final FocusNode? focusNode;

/// {@template flutter.widgets.Focus.autofocus}
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter/lib/src/widgets/focus_traversal.dart
Expand Up @@ -200,7 +200,7 @@ abstract class FocusTraversalPolicy with Diagnosticable {
///
/// See also:
///
/// * [previous], the function that is called to move the focus to the next node.
/// * [previous], the function that is called to move the focus to the previous node.
/// * [DirectionalFocusTraversalPolicyMixin.findFirstFocusInDirection], a
/// function that finds the first focusable widget in a particular direction.
FocusNode findLastFocus(FocusNode currentNode, {bool ignoreCurrentFocus = false}) {
Expand Down Expand Up @@ -1139,7 +1139,7 @@ class ReadingOrderTraversalPolicy extends FocusTraversalPolicy with DirectionalF
// It has to have at least topmost in it if the topmost is not degenerate.
assert(topmost.rect.isEmpty || inBandOfTop.isNotEmpty);

// The topmost rect in is in a band by itself, so just return that one.
// The topmost rect is in a band by itself, so just return that one.
if (inBandOfTop.length <= 1) {
return topmost;
}
Expand Down
7 changes: 3 additions & 4 deletions packages/flutter/lib/src/widgets/shortcuts.dart
Expand Up @@ -90,7 +90,6 @@ class KeySet<T extends KeyboardKey> {
&& setEquals<T>(other._keys, _keys);
}


// Cached hash code value. Improves [hashCode] performance by 27%-900%,
// depending on key set size and read/write ratio.
@override
Expand Down Expand Up @@ -334,8 +333,8 @@ class LogicalKeySet extends KeySet<LogicalKeyboardKey> with Diagnosticable
}
}

/// A [DiagnosticsProperty] which handles formatting a `Map<LogicalKeySet,
/// Intent>` (the same type as the [Shortcuts.shortcuts] property) so that its
/// A [DiagnosticsProperty] which handles formatting a `Map<LogicalKeySet, Intent>`
/// (the same type as the [Shortcuts.shortcuts] property) so that its
/// diagnostic output is human-readable.
class ShortcutMapProperty extends DiagnosticsProperty<Map<ShortcutActivator, Intent>> {
/// Create a diagnostics property for `Map<ShortcutActivator, Intent>` objects,
Expand Down Expand Up @@ -1183,7 +1182,7 @@ class ShortcutRegistryEntry {
///
/// The registry may be listened to (with [addListener]/[removeListener]) for
/// change notifications when the registered shortcuts change. Change
/// notifications take place after the the current frame is drawn, so that
/// notifications take place after the current frame is drawn, so that
/// widgets that are not descendants of the registry can listen to it (e.g. in
/// overlays).
class ShortcutRegistry with ChangeNotifier {
Expand Down
4 changes: 4 additions & 0 deletions packages/flutter/test/widgets/actions_test.dart
Expand Up @@ -74,6 +74,7 @@ void main() {
expect(result, isTrue);
expect(invoked, isTrue);
});

testWidgets('Actions widget can invoke actions with default dispatcher and maybeInvoke', (WidgetTester tester) async {
final GlobalKey containerKey = GlobalKey();
bool invoked = false;
Expand Down Expand Up @@ -1083,6 +1084,7 @@ void main() {
action._testInvoke(intent);
expect(passedIntent, equals(intent));
});

testWidgets('VoidCallbackAction', (WidgetTester tester) async {
bool called = false;
void testCallback() {
Expand Down Expand Up @@ -1121,6 +1123,7 @@ void main() {

expect(description, isEmpty);
});

testWidgets('default Actions debugFillProperties', (WidgetTester tester) async {
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();

Expand All @@ -1146,6 +1149,7 @@ void main() {
]),
);
});

testWidgets('Actions implements debugFillProperties', (WidgetTester tester) async {
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();

Expand Down
102 changes: 48 additions & 54 deletions packages/flutter/test/widgets/focus_scope_test.dart
Expand Up @@ -420,7 +420,7 @@ void main() {
expect(find.text('b'), findsOneWidget);
});

testWidgets('Adding a new FocusScope attaches the child it to its parent.', (WidgetTester tester) async {
testWidgets('Adding a new FocusScope attaches the child to its parent.', (WidgetTester tester) async {
final GlobalKey<TestFocusState> keyA = GlobalKey();
final FocusScopeNode parentFocusScope = FocusScopeNode(debugLabel: 'Parent Scope Node');
final FocusScopeNode childFocusScope = FocusScopeNode(debugLabel: 'Child Scope Node');
Expand Down Expand Up @@ -540,24 +540,24 @@ void main() {

await tester.pumpWidget(
FocusScope.withExternalFocusNode(
focusScopeNode: topNode,
child: Column(
children: <Widget>[
FocusScope.withExternalFocusNode(
focusScopeNode: parentNode,
child: const SizedBox(),
focusScopeNode: topNode,
child: Column(
children: <Widget>[
FocusScope.withExternalFocusNode(
focusScopeNode: parentNode,
child: const SizedBox(),
),
FocusScope.withExternalFocusNode(
focusScopeNode: childNode,
parentNode: parentNode,
child: const Focus(
autofocus: true,
child: SizedBox(),
),
FocusScope.withExternalFocusNode(
focusScopeNode: childNode,
parentNode: parentNode,
child: const Focus(
autofocus: true,
child: SizedBox(),
),
)
],
),
)
],
),
),
);
await tester.pump();

Expand All @@ -568,27 +568,27 @@ void main() {
// Check that inserting a Focus in between doesn't reparent the child.
await tester.pumpWidget(
FocusScope.withExternalFocusNode(
focusScopeNode: topNode,
child: Column(
children: <Widget>[
FocusScope.withExternalFocusNode(
focusScopeNode: parentNode,
child: const SizedBox(),
),
FocusScope.withExternalFocusNode(
focusScopeNode: insertedNode,
child: FocusScope.withExternalFocusNode(
focusScopeNode: childNode,
parentNode: parentNode,
child: const Focus(
focusScopeNode: topNode,
child: Column(
children: <Widget>[
FocusScope.withExternalFocusNode(
focusScopeNode: parentNode,
child: const SizedBox(),
),
FocusScope.withExternalFocusNode(
focusScopeNode: insertedNode,
child: FocusScope.withExternalFocusNode(
focusScopeNode: childNode,
parentNode: parentNode,
child: const Focus(
autofocus: true,
child: SizedBox(),
),
),
)
],
),
),
)
],
),
),
);
await tester.pump();

Expand Down Expand Up @@ -1673,6 +1673,7 @@ void main() {
await pumpTest(traverseScope1: true);
expect(scope1.traversalDescendants, equals(<FocusNode>[focus2, focus1, scope2]));
});

testWidgets('descendantsAreFocusable works as expected.', (WidgetTester tester) async {
final GlobalKey key1 = GlobalKey(debugLabel: '1');
final GlobalKey key2 = GlobalKey(debugLabel: '2');
Expand Down Expand Up @@ -1756,13 +1757,11 @@ void main() {
final GlobalKey key1 = GlobalKey(debugLabel: '1');
final FocusNode focusNode = FocusNode();
bool? keyEventHandled;
// ignore: prefer_function_declarations_over_variables
final FocusOnKeyCallback handleCallback = (FocusNode node, RawKeyEvent event) {
KeyEventResult handleCallback(FocusNode node, RawKeyEvent event) {
keyEventHandled = true;
return KeyEventResult.handled;
};
// ignore: prefer_function_declarations_over_variables
final FocusOnKeyCallback ignoreCallback = (FocusNode node, RawKeyEvent event) => KeyEventResult.ignored;
}
KeyEventResult ignoreCallback(FocusNode node, RawKeyEvent event) => KeyEventResult.ignored;
Focus focusWidget = Focus(
onKey: ignoreCallback, // This one does nothing.
focusNode: focusNode,
Expand Down Expand Up @@ -1807,13 +1806,11 @@ void main() {
final GlobalKey key1 = GlobalKey(debugLabel: '1');
final FocusNode focusNode = FocusNode();
bool? keyEventHandled;
// ignore: prefer_function_declarations_over_variables
final FocusOnKeyEventCallback handleEventCallback = (FocusNode node, KeyEvent event) {
KeyEventResult handleEventCallback(FocusNode node, KeyEvent event) {
keyEventHandled = true;
return KeyEventResult.handled;
};
// ignore: prefer_function_declarations_over_variables
final FocusOnKeyEventCallback ignoreEventCallback = (FocusNode node, KeyEvent event) => KeyEventResult.ignored;
}
KeyEventResult ignoreEventCallback(FocusNode node, KeyEvent event) => KeyEventResult.ignored;
Focus focusWidget = Focus(
onKeyEvent: ignoreEventCallback, // This one does nothing.
focusNode: focusNode,
Expand Down Expand Up @@ -1858,20 +1855,16 @@ void main() {
final GlobalKey key1 = GlobalKey(debugLabel: '1');
final FocusNode focusNode = FocusNode();
bool? keyEventHandled;
// ignore: prefer_function_declarations_over_variables
final FocusOnKeyCallback handleCallback = (FocusNode node, RawKeyEvent event) {
KeyEventResult handleCallback(FocusNode node, RawKeyEvent event) {
keyEventHandled = true;
return KeyEventResult.handled;
};
// ignore: prefer_function_declarations_over_variables
final FocusOnKeyEventCallback handleEventCallback = (FocusNode node, KeyEvent event) {
}
KeyEventResult handleEventCallback(FocusNode node, KeyEvent event) {
keyEventHandled = true;
return KeyEventResult.handled;
};
// ignore: prefer_function_declarations_over_variables
final FocusOnKeyCallback ignoreCallback = (FocusNode node, RawKeyEvent event) => KeyEventResult.ignored;
// ignore: prefer_function_declarations_over_variables
final FocusOnKeyEventCallback ignoreEventCallback = (FocusNode node, KeyEvent event) => KeyEventResult.ignored;
}
KeyEventResult ignoreCallback(FocusNode node, RawKeyEvent event) => KeyEventResult.ignored;
KeyEventResult ignoreEventCallback(FocusNode node, KeyEvent event) => KeyEventResult.ignored;
focusNode.onKey = ignoreCallback;
focusNode.onKeyEvent = ignoreEventCallback;
focusNode.descendantsAreFocusable = false;
Expand Down Expand Up @@ -1974,6 +1967,7 @@ void main() {
expect(containerNode.hasFocus, isFalse);
expect(unfocusableNode.hasFocus, isFalse);
});

// Regression test for https://github.com/flutter/flutter/issues/61700
testWidgets("ExcludeFocus doesn't transfer focus to another descendant.", (WidgetTester tester) async {
final FocusNode parentFocusNode = FocusNode(debugLabel: 'group');
Expand Down
11 changes: 6 additions & 5 deletions packages/flutter/test/widgets/focus_traversal_test.dart
Expand Up @@ -2153,6 +2153,7 @@ void main() {
expect(events.length, 2);
}, variant: KeySimulatorTransitModeVariant.all());
});

group(FocusTraversalGroup, () {
testWidgets("Focus traversal group doesn't introduce a Semantics node", (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);
Expand Down Expand Up @@ -2381,11 +2382,11 @@ void main() {
final SemanticsTester semantics = SemanticsTester(tester);
final FocusNode focusNode = FocusNode();
await tester.pumpWidget(
RawKeyboardListener(
focusNode: focusNode,
includeSemantics: false,
child: Container(),
),
RawKeyboardListener(
focusNode: focusNode,
includeSemantics: false,
child: Container(),
),
);
final TestSemantics expectedSemantics = TestSemantics.root();
expect(semantics, hasSemantics(expectedSemantics));
Expand Down

0 comments on commit 0eaa83a

Please sign in to comment.