Skip to content

Commit 0eaa83a

Browse files
authored
Fix some Focus related documentation typos (#118576)
* Fix focus area documentation typos * Restore intentional spaces that illustrate bigger buttons
1 parent f989d55 commit 0eaa83a

File tree

9 files changed

+99
-82
lines changed

9 files changed

+99
-82
lines changed

packages/flutter/lib/src/widgets/actions.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ class Actions extends StatefulWidget {
954954
final Action<T>? result = _castAction(actions, intent: intent);
955955
if (result != null && result.isEnabled(intent)) {
956956
// Invoke the action we found using the relevant dispatcher from the Actions
957-
// Element we found.
957+
// element we found.
958958
returnValue = _findDispatcher(element).invokeAction(result, intent, context);
959959
}
960960
return result != null;
@@ -1478,7 +1478,8 @@ class ActivateIntent extends Intent {
14781478
/// * [WidgetsApp.shortcuts], which defines the shortcuts to use in an
14791479
/// application (and defaults to [WidgetsApp.defaultShortcuts]).
14801480
class ButtonActivateIntent extends Intent {
1481-
/// Creates an intent that the currently focused control, if it's a button.
1481+
/// Creates an intent that activates the currently focused control,
1482+
/// if it's a button.
14821483
const ButtonActivateIntent();
14831484
}
14841485

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

15831584
// The default action to invoke if an enabled override Action can't be found
1584-
// using [lookupContext];
1585+
// using [lookupContext].
15851586
Action<T> get defaultAction;
15861587

15871588
// The [BuildContext] used to find the override of this [Action].

packages/flutter/lib/src/widgets/focus_manager.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class _Autofocus {
110110
// The widget tree is responsible for calling reparent/detach on attached
111111
// nodes to keep their parent/manager information up-to-date, so here we can
112112
// safely check if the scope/node involved in each autofocus request is
113-
// still attached, and discard the ones are no longer attached to the
113+
// still attached, and discard the ones which are no longer attached to the
114114
// original manager.
115115
void applyIfValid(FocusManager manager) {
116116
final bool shouldApply = (scope.parent != null || identical(scope, manager.rootScope))
@@ -128,8 +128,8 @@ class _Autofocus {
128128

129129
/// An attachment point for a [FocusNode].
130130
///
131-
/// Using a [FocusAttachment] is rarely needed, unless you are building
132-
/// something akin to the [Focus] or [FocusScope] widgets from scratch.
131+
/// Using a [FocusAttachment] is rarely needed, unless building something
132+
/// akin to the [Focus] or [FocusScope] widgets from scratch.
133133
///
134134
/// Once created, a [FocusNode] must be attached to the widget tree by its
135135
/// _host_ [StatefulWidget] via a [FocusAttachment] object. [FocusAttachment]s
@@ -261,8 +261,8 @@ enum UnfocusDisposition {
261261
///
262262
/// _Please see the [Focus] and [FocusScope] widgets, which are utility widgets
263263
/// that manage their own [FocusNode]s and [FocusScopeNode]s, respectively. If
264-
/// they aren't appropriate, [FocusNode]s can be managed directly, but doing
265-
/// this yourself is rare._
264+
/// they aren't appropriate, [FocusNode]s can be managed directly, but doing this
265+
/// is rare._
266266
///
267267
/// [FocusNode]s are persistent objects that form a _focus tree_ that is a
268268
/// representation of the widgets in the hierarchy that are interested in focus.
@@ -1405,8 +1405,8 @@ enum FocusHighlightStrategy {
14051405
/// The focus manager is responsible for tracking which [FocusNode] has the
14061406
/// primary input focus (the [primaryFocus]), holding the [FocusScopeNode] that
14071407
/// is the root of the focus tree (the [rootScope]), and what the current
1408-
/// [highlightMode] is. It also distributes key events from [RawKeyboard] to the
1409-
/// nodes in the focus tree.
1408+
/// [highlightMode] is. It also distributes key events from [KeyEventManager]
1409+
/// to the nodes in the focus tree.
14101410
///
14111411
/// The singleton [FocusManager] instance is held by the [WidgetsBinding] as
14121412
/// [WidgetsBinding.focusManager], and can be conveniently accessed using the

packages/flutter/lib/src/widgets/focus_scope.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class Focus extends StatefulWidget {
195195
/// {@endtemplate}
196196
///
197197
/// A non-null [focusNode] must be supplied if using the
198-
/// [Focus.withExternalFocusNode] constructor is used.
198+
/// [Focus.withExternalFocusNode] constructor.
199199
final FocusNode? focusNode;
200200

201201
/// {@template flutter.widgets.Focus.autofocus}

packages/flutter/lib/src/widgets/focus_traversal.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ abstract class FocusTraversalPolicy with Diagnosticable {
200200
///
201201
/// See also:
202202
///
203-
/// * [previous], the function that is called to move the focus to the next node.
203+
/// * [previous], the function that is called to move the focus to the previous node.
204204
/// * [DirectionalFocusTraversalPolicyMixin.findFirstFocusInDirection], a
205205
/// function that finds the first focusable widget in a particular direction.
206206
FocusNode findLastFocus(FocusNode currentNode, {bool ignoreCurrentFocus = false}) {
@@ -1139,7 +1139,7 @@ class ReadingOrderTraversalPolicy extends FocusTraversalPolicy with DirectionalF
11391139
// It has to have at least topmost in it if the topmost is not degenerate.
11401140
assert(topmost.rect.isEmpty || inBandOfTop.isNotEmpty);
11411141

1142-
// The topmost rect in is in a band by itself, so just return that one.
1142+
// The topmost rect is in a band by itself, so just return that one.
11431143
if (inBandOfTop.length <= 1) {
11441144
return topmost;
11451145
}

packages/flutter/lib/src/widgets/shortcuts.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ class KeySet<T extends KeyboardKey> {
9090
&& setEquals<T>(other._keys, _keys);
9191
}
9292

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

337-
/// A [DiagnosticsProperty] which handles formatting a `Map<LogicalKeySet,
338-
/// Intent>` (the same type as the [Shortcuts.shortcuts] property) so that its
336+
/// A [DiagnosticsProperty] which handles formatting a `Map<LogicalKeySet, Intent>`
337+
/// (the same type as the [Shortcuts.shortcuts] property) so that its
339338
/// diagnostic output is human-readable.
340339
class ShortcutMapProperty extends DiagnosticsProperty<Map<ShortcutActivator, Intent>> {
341340
/// Create a diagnostics property for `Map<ShortcutActivator, Intent>` objects,
@@ -1183,7 +1182,7 @@ class ShortcutRegistryEntry {
11831182
///
11841183
/// The registry may be listened to (with [addListener]/[removeListener]) for
11851184
/// change notifications when the registered shortcuts change. Change
1186-
/// notifications take place after the the current frame is drawn, so that
1185+
/// notifications take place after the current frame is drawn, so that
11871186
/// widgets that are not descendants of the registry can listen to it (e.g. in
11881187
/// overlays).
11891188
class ShortcutRegistry with ChangeNotifier {

packages/flutter/test/widgets/actions_test.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ void main() {
7474
expect(result, isTrue);
7575
expect(invoked, isTrue);
7676
});
77+
7778
testWidgets('Actions widget can invoke actions with default dispatcher and maybeInvoke', (WidgetTester tester) async {
7879
final GlobalKey containerKey = GlobalKey();
7980
bool invoked = false;
@@ -1083,6 +1084,7 @@ void main() {
10831084
action._testInvoke(intent);
10841085
expect(passedIntent, equals(intent));
10851086
});
1087+
10861088
testWidgets('VoidCallbackAction', (WidgetTester tester) async {
10871089
bool called = false;
10881090
void testCallback() {
@@ -1121,6 +1123,7 @@ void main() {
11211123

11221124
expect(description, isEmpty);
11231125
});
1126+
11241127
testWidgets('default Actions debugFillProperties', (WidgetTester tester) async {
11251128
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
11261129

@@ -1146,6 +1149,7 @@ void main() {
11461149
]),
11471150
);
11481151
});
1152+
11491153
testWidgets('Actions implements debugFillProperties', (WidgetTester tester) async {
11501154
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
11511155

packages/flutter/test/widgets/focus_scope_test.dart

Lines changed: 48 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ void main() {
420420
expect(find.text('b'), findsOneWidget);
421421
});
422422

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

541541
await tester.pumpWidget(
542542
FocusScope.withExternalFocusNode(
543-
focusScopeNode: topNode,
544-
child: Column(
545-
children: <Widget>[
546-
FocusScope.withExternalFocusNode(
547-
focusScopeNode: parentNode,
548-
child: const SizedBox(),
543+
focusScopeNode: topNode,
544+
child: Column(
545+
children: <Widget>[
546+
FocusScope.withExternalFocusNode(
547+
focusScopeNode: parentNode,
548+
child: const SizedBox(),
549+
),
550+
FocusScope.withExternalFocusNode(
551+
focusScopeNode: childNode,
552+
parentNode: parentNode,
553+
child: const Focus(
554+
autofocus: true,
555+
child: SizedBox(),
549556
),
550-
FocusScope.withExternalFocusNode(
551-
focusScopeNode: childNode,
552-
parentNode: parentNode,
553-
child: const Focus(
554-
autofocus: true,
555-
child: SizedBox(),
556-
),
557-
)
558-
],
559-
),
557+
)
558+
],
560559
),
560+
),
561561
);
562562
await tester.pump();
563563

@@ -568,27 +568,27 @@ void main() {
568568
// Check that inserting a Focus in between doesn't reparent the child.
569569
await tester.pumpWidget(
570570
FocusScope.withExternalFocusNode(
571-
focusScopeNode: topNode,
572-
child: Column(
573-
children: <Widget>[
574-
FocusScope.withExternalFocusNode(
575-
focusScopeNode: parentNode,
576-
child: const SizedBox(),
577-
),
578-
FocusScope.withExternalFocusNode(
579-
focusScopeNode: insertedNode,
580-
child: FocusScope.withExternalFocusNode(
581-
focusScopeNode: childNode,
582-
parentNode: parentNode,
583-
child: const Focus(
571+
focusScopeNode: topNode,
572+
child: Column(
573+
children: <Widget>[
574+
FocusScope.withExternalFocusNode(
575+
focusScopeNode: parentNode,
576+
child: const SizedBox(),
577+
),
578+
FocusScope.withExternalFocusNode(
579+
focusScopeNode: insertedNode,
580+
child: FocusScope.withExternalFocusNode(
581+
focusScopeNode: childNode,
582+
parentNode: parentNode,
583+
child: const Focus(
584584
autofocus: true,
585585
child: SizedBox(),
586586
),
587-
),
588-
)
589-
],
590-
),
587+
),
588+
)
589+
],
591590
),
591+
),
592592
);
593593
await tester.pump();
594594

@@ -1673,6 +1673,7 @@ void main() {
16731673
await pumpTest(traverseScope1: true);
16741674
expect(scope1.traversalDescendants, equals(<FocusNode>[focus2, focus1, scope2]));
16751675
});
1676+
16761677
testWidgets('descendantsAreFocusable works as expected.', (WidgetTester tester) async {
16771678
final GlobalKey key1 = GlobalKey(debugLabel: '1');
16781679
final GlobalKey key2 = GlobalKey(debugLabel: '2');
@@ -1756,13 +1757,11 @@ void main() {
17561757
final GlobalKey key1 = GlobalKey(debugLabel: '1');
17571758
final FocusNode focusNode = FocusNode();
17581759
bool? keyEventHandled;
1759-
// ignore: prefer_function_declarations_over_variables
1760-
final FocusOnKeyCallback handleCallback = (FocusNode node, RawKeyEvent event) {
1760+
KeyEventResult handleCallback(FocusNode node, RawKeyEvent event) {
17611761
keyEventHandled = true;
17621762
return KeyEventResult.handled;
1763-
};
1764-
// ignore: prefer_function_declarations_over_variables
1765-
final FocusOnKeyCallback ignoreCallback = (FocusNode node, RawKeyEvent event) => KeyEventResult.ignored;
1763+
}
1764+
KeyEventResult ignoreCallback(FocusNode node, RawKeyEvent event) => KeyEventResult.ignored;
17661765
Focus focusWidget = Focus(
17671766
onKey: ignoreCallback, // This one does nothing.
17681767
focusNode: focusNode,
@@ -1807,13 +1806,11 @@ void main() {
18071806
final GlobalKey key1 = GlobalKey(debugLabel: '1');
18081807
final FocusNode focusNode = FocusNode();
18091808
bool? keyEventHandled;
1810-
// ignore: prefer_function_declarations_over_variables
1811-
final FocusOnKeyEventCallback handleEventCallback = (FocusNode node, KeyEvent event) {
1809+
KeyEventResult handleEventCallback(FocusNode node, KeyEvent event) {
18121810
keyEventHandled = true;
18131811
return KeyEventResult.handled;
1814-
};
1815-
// ignore: prefer_function_declarations_over_variables
1816-
final FocusOnKeyEventCallback ignoreEventCallback = (FocusNode node, KeyEvent event) => KeyEventResult.ignored;
1812+
}
1813+
KeyEventResult ignoreEventCallback(FocusNode node, KeyEvent event) => KeyEventResult.ignored;
18171814
Focus focusWidget = Focus(
18181815
onKeyEvent: ignoreEventCallback, // This one does nothing.
18191816
focusNode: focusNode,
@@ -1858,20 +1855,16 @@ void main() {
18581855
final GlobalKey key1 = GlobalKey(debugLabel: '1');
18591856
final FocusNode focusNode = FocusNode();
18601857
bool? keyEventHandled;
1861-
// ignore: prefer_function_declarations_over_variables
1862-
final FocusOnKeyCallback handleCallback = (FocusNode node, RawKeyEvent event) {
1858+
KeyEventResult handleCallback(FocusNode node, RawKeyEvent event) {
18631859
keyEventHandled = true;
18641860
return KeyEventResult.handled;
1865-
};
1866-
// ignore: prefer_function_declarations_over_variables
1867-
final FocusOnKeyEventCallback handleEventCallback = (FocusNode node, KeyEvent event) {
1861+
}
1862+
KeyEventResult handleEventCallback(FocusNode node, KeyEvent event) {
18681863
keyEventHandled = true;
18691864
return KeyEventResult.handled;
1870-
};
1871-
// ignore: prefer_function_declarations_over_variables
1872-
final FocusOnKeyCallback ignoreCallback = (FocusNode node, RawKeyEvent event) => KeyEventResult.ignored;
1873-
// ignore: prefer_function_declarations_over_variables
1874-
final FocusOnKeyEventCallback ignoreEventCallback = (FocusNode node, KeyEvent event) => KeyEventResult.ignored;
1865+
}
1866+
KeyEventResult ignoreCallback(FocusNode node, RawKeyEvent event) => KeyEventResult.ignored;
1867+
KeyEventResult ignoreEventCallback(FocusNode node, KeyEvent event) => KeyEventResult.ignored;
18751868
focusNode.onKey = ignoreCallback;
18761869
focusNode.onKeyEvent = ignoreEventCallback;
18771870
focusNode.descendantsAreFocusable = false;
@@ -1974,6 +1967,7 @@ void main() {
19741967
expect(containerNode.hasFocus, isFalse);
19751968
expect(unfocusableNode.hasFocus, isFalse);
19761969
});
1970+
19771971
// Regression test for https://github.com/flutter/flutter/issues/61700
19781972
testWidgets("ExcludeFocus doesn't transfer focus to another descendant.", (WidgetTester tester) async {
19791973
final FocusNode parentFocusNode = FocusNode(debugLabel: 'group');

packages/flutter/test/widgets/focus_traversal_test.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2153,6 +2153,7 @@ void main() {
21532153
expect(events.length, 2);
21542154
}, variant: KeySimulatorTransitModeVariant.all());
21552155
});
2156+
21562157
group(FocusTraversalGroup, () {
21572158
testWidgets("Focus traversal group doesn't introduce a Semantics node", (WidgetTester tester) async {
21582159
final SemanticsTester semantics = SemanticsTester(tester);
@@ -2381,11 +2382,11 @@ void main() {
23812382
final SemanticsTester semantics = SemanticsTester(tester);
23822383
final FocusNode focusNode = FocusNode();
23832384
await tester.pumpWidget(
2384-
RawKeyboardListener(
2385-
focusNode: focusNode,
2386-
includeSemantics: false,
2387-
child: Container(),
2388-
),
2385+
RawKeyboardListener(
2386+
focusNode: focusNode,
2387+
includeSemantics: false,
2388+
child: Container(),
2389+
),
23892390
);
23902391
final TestSemantics expectedSemantics = TestSemantics.root();
23912392
expect(semantics, hasSemantics(expectedSemantics));

0 commit comments

Comments
 (0)