Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions examples/ui/actions_and_shortcuts/lib/copyable_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ class CopyableTextField extends StatefulWidget {

class _CopyableTextFieldState extends State<CopyableTextField> {
late final TextEditingController controller = TextEditingController();
late final FocusNode focusNode = FocusNode();

@override
void dispose() {
controller.dispose();
focusNode.dispose();
super.dispose();
}

Expand All @@ -28,7 +30,7 @@ class _CopyableTextFieldState extends State<CopyableTextField> {
actions: <Type, Action<Intent>>{
ClearIntent: ClearAction(controller),
CopyIntent: CopyAction(controller),
SelectAllIntent: SelectAllAction(controller),
SelectAllIntent: SelectAllAction(controller, focusNode),
},
child: Builder(
builder: (context) {
Expand All @@ -37,7 +39,12 @@ class _CopyableTextFieldState extends State<CopyableTextField> {
child: Row(
children: <Widget>[
const Spacer(),
Expanded(child: TextField(controller: controller)),
Expanded(
child: TextField(
controller: controller,
focusNode: focusNode,
),
),
IconButton(
icon: const Icon(Icons.copy),
onPressed: Actions.handler<CopyIntent>(
Expand Down Expand Up @@ -145,9 +152,10 @@ class SelectAllIntent extends Intent {
/// An action that is bound to SelectAllAction that selects all text in its
/// TextEditingController.
class SelectAllAction extends Action<SelectAllIntent> {
SelectAllAction(this.controller);
SelectAllAction(this.controller, this.focusNode);

final TextEditingController controller;
final FocusNode focusNode;

@override
Object? invoke(covariant SelectAllIntent intent) {
Expand All @@ -157,6 +165,8 @@ class SelectAllAction extends Action<SelectAllIntent> {
affinity: controller.selection.affinity,
);

focusNode.requestFocus();

return null;
}
}
Expand Down
16 changes: 13 additions & 3 deletions src/content/ui/interactivity/actions-and-shortcuts.md
Original file line number Diff line number Diff line change
Expand Up @@ -446,10 +446,12 @@ class CopyableTextField extends StatefulWidget {

class _CopyableTextFieldState extends State<CopyableTextField> {
late final TextEditingController controller = TextEditingController();
late final FocusNode focusNode = FocusNode();

@override
void dispose() {
controller.dispose();
focusNode.dispose();
super.dispose();
}

Expand All @@ -460,7 +462,7 @@ class _CopyableTextFieldState extends State<CopyableTextField> {
actions: <Type, Action<Intent>>{
ClearIntent: ClearAction(controller),
CopyIntent: CopyAction(controller),
SelectAllIntent: SelectAllAction(controller),
SelectAllIntent: SelectAllAction(controller, focusNode),
},
child: Builder(
builder: (context) {
Expand All @@ -469,7 +471,12 @@ class _CopyableTextFieldState extends State<CopyableTextField> {
child: Row(
children: <Widget>[
const Spacer(),
Expanded(child: TextField(controller: controller)),
Expanded(
child: TextField(
controller: controller,
focusNode: focusNode,
),
),
IconButton(
icon: const Icon(Icons.copy),
onPressed: Actions.handler<CopyIntent>(
Expand Down Expand Up @@ -577,9 +584,10 @@ class SelectAllIntent extends Intent {
/// An action that is bound to SelectAllAction that selects all text in its
/// TextEditingController.
class SelectAllAction extends Action<SelectAllIntent> {
SelectAllAction(this.controller);
SelectAllAction(this.controller, this.focusNode);

final TextEditingController controller;
final FocusNode focusNode;

@override
Object? invoke(covariant SelectAllIntent intent) {
Expand All @@ -589,6 +597,8 @@ class SelectAllAction extends Action<SelectAllIntent> {
affinity: controller.selection.affinity,
);

focusNode.requestFocus();

return null;
}
}
Expand Down