Unverified Commit 1793108b authored by Greg Spencer's avatar Greg Spencer Committed by GitHub

Add additional focus samples. (#50846)

parent 7a83c6fc
...@@ -62,6 +62,54 @@ export 'package:flutter/services.dart' show SmartQuotesType, SmartDashesType; ...@@ -62,6 +62,54 @@ export 'package:flutter/services.dart' show SmartQuotesType, SmartDashesType;
/// ``` /// ```
/// {@end-tool} /// {@end-tool}
/// ///
/// {@tool dartpad --template=stateful_widget_material}
/// This example shows how to move the focus to the next field when the user
/// presses the ENTER key.
///
/// ```dart imports
/// import 'package:flutter/services.dart';
/// ```
///
/// ```dart
/// Widget build(BuildContext context) {
/// return Material(
/// child: Center(
/// child: Shortcuts(
/// shortcuts: <LogicalKeySet, Intent>{
/// // Pressing enter on the field will now move to the next field.
/// LogicalKeySet(LogicalKeyboardKey.enter):
/// Intent(NextFocusAction.key),
/// },
/// child: FocusTraversalGroup(
/// child: Form(
/// autovalidate: true,
/// onChanged: () {
/// Form.of(primaryFocus.context).save();
/// },
/// child: Wrap(
/// children: List<Widget>.generate(5, (int index) {
/// return Padding(
/// padding: const EdgeInsets.all(8.0),
/// child: ConstrainedBox(
/// constraints: BoxConstraints.tight(Size(200, 50)),
/// child: TextFormField(
/// onSaved: (String value) {
/// print('Value for field $index saved as "$value"');
/// },
/// ),
/// ),
/// );
/// }),
/// ),
/// ),
/// ),
/// ),
/// ),
/// );
/// }
/// ```
/// {@end-tool}
///
/// See also: /// See also:
/// ///
/// * <https://material.io/design/components/text-fields.html> /// * <https://material.io/design/components/text-fields.html>
......
...@@ -374,12 +374,14 @@ class Actions extends InheritedWidget { ...@@ -374,12 +374,14 @@ class Actions extends InheritedWidget {
/// {@tool dartpad --template=stateful_widget_material} /// {@tool dartpad --template=stateful_widget_material}
/// This example shows how keyboard interaction can be added to a custom control /// This example shows how keyboard interaction can be added to a custom control
/// that changes color when hovered and focused, and can toggle a light when /// that changes color when hovered and focused, and can toggle a light when
/// activated, either by touch or by hitting the `X` key on the keyboard. /// activated, either by touch or by hitting the `X` key on the keyboard when
/// the "And Me" button has the keyboard focus (be sure to use TAB to move the
/// focus to the "And Me" button before trying it out).
/// ///
/// This example defines its own key binding for the `X` key, but in this case, /// This example defines its own key binding for the `X` key, but in this case,
/// there is also a default key binding for [ActivateAction] in the default key /// there is also a default key binding for [ActivateAction] in the default key
/// bindings created by [WidgetsApp] (the parent for [MaterialApp], and /// bindings created by [WidgetsApp] (the parent for [MaterialApp], and
/// [CupertinoApp]), so the `ENTER` key will also activate the control. /// [CupertinoApp]), so the `ENTER` key will also activate the buttons.
/// ///
/// ```dart imports /// ```dart imports
/// import 'package:flutter/services.dart'; /// import 'package:flutter/services.dart';
......
...@@ -951,8 +951,8 @@ class _ReadingOrderDirectionalGroupData extends Diagnosticable { ...@@ -951,8 +951,8 @@ class _ReadingOrderDirectionalGroupData extends Diagnosticable {
/// 3. Pick the closest to the beginning of the reading order from among the /// 3. Pick the closest to the beginning of the reading order from among the
/// nodes discovered above. /// nodes discovered above.
/// ///
/// It uses the ambient [Directionality] in the context for the enclosing scope /// It uses the ambient [Directionality] in the context for the enclosing
/// to determine which direction is "reading order". /// [FocusTraversalGroup] to determine which direction is "reading order".
/// ///
/// See also: /// See also:
/// ///
...@@ -1296,11 +1296,14 @@ class _OrderedFocusInfo { ...@@ -1296,11 +1296,14 @@ class _OrderedFocusInfo {
/// ), /// ),
/// ); /// );
/// } /// }
/// ```
/// {@end-tool} /// {@end-tool}
/// ///
/// See also: /// See also:
/// ///
/// * [WidgetOrderFocusTraversalPolicy], a policy that relies on the widget /// * [FocusTraversalGroup], a widget that groups together and imposes a
/// traversal policy on the [Focus] nodes below it in the widget hierarchy.
/// * [WidgetOrderTraversalPolicy], a policy that relies on the widget
/// creation order to describe the order of traversal. /// creation order to describe the order of traversal.
/// * [ReadingOrderTraversalPolicy], a policy that describes the order as the /// * [ReadingOrderTraversalPolicy], a policy that describes the order as the
/// natural "reading order" for the current [Directionality]. /// natural "reading order" for the current [Directionality].
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment