Move text editing Actions to EditableTextState (#90684)
This commit is contained in:
@@ -18,7 +18,7 @@ void main() {
|
||||
}
|
||||
|
||||
// This implements a custom phone number input field that handles the
|
||||
// [DeleteTextIntent] intent.
|
||||
// [DeleteCharacterIntent] intent.
|
||||
class DigitInput extends StatefulWidget {
|
||||
const DigitInput({
|
||||
Key? key,
|
||||
@@ -38,9 +38,9 @@ class DigitInput extends StatefulWidget {
|
||||
}
|
||||
|
||||
class DigitInputState extends State<DigitInput> {
|
||||
late final Action<DeleteTextIntent> _deleteTextAction =
|
||||
CallbackAction<DeleteTextIntent>(
|
||||
onInvoke: (DeleteTextIntent intent) {
|
||||
late final Action<DeleteCharacterIntent> _deleteTextAction =
|
||||
CallbackAction<DeleteCharacterIntent>(
|
||||
onInvoke: (DeleteCharacterIntent intent) {
|
||||
// For simplicity we delete everything in the section.
|
||||
widget.controller.clear();
|
||||
},
|
||||
@@ -50,8 +50,8 @@ class DigitInputState extends State<DigitInput> {
|
||||
Widget build(BuildContext context) {
|
||||
return Actions(
|
||||
actions: <Type, Action<Intent>>{
|
||||
// Make the default `DeleteTextIntent` handler overridable.
|
||||
DeleteTextIntent: Action<DeleteTextIntent>.overridable(
|
||||
// Make the default `DeleteCharacterIntent` handler overridable.
|
||||
DeleteCharacterIntent: Action<DeleteCharacterIntent>.overridable(
|
||||
defaultAction: _deleteTextAction, context: context),
|
||||
},
|
||||
child: TextField(
|
||||
@@ -79,12 +79,12 @@ class SimpleUSPhoneNumberEntry extends StatefulWidget {
|
||||
_SimpleUSPhoneNumberEntryState();
|
||||
}
|
||||
|
||||
class _DeleteDigit extends Action<DeleteTextIntent> {
|
||||
class _DeleteDigit extends Action<DeleteCharacterIntent> {
|
||||
_DeleteDigit(this.state);
|
||||
|
||||
final _SimpleUSPhoneNumberEntryState state;
|
||||
@override
|
||||
Object? invoke(DeleteTextIntent intent) {
|
||||
Object? invoke(DeleteCharacterIntent intent) {
|
||||
assert(callingAction != null);
|
||||
callingAction?.invoke(intent);
|
||||
|
||||
@@ -116,7 +116,7 @@ class _SimpleUSPhoneNumberEntryState extends State<SimpleUSPhoneNumberEntry> {
|
||||
Widget build(BuildContext context) {
|
||||
return Actions(
|
||||
actions: <Type, Action<Intent>>{
|
||||
DeleteTextIntent: _DeleteDigit(this),
|
||||
DeleteCharacterIntent: _DeleteDigit(this),
|
||||
},
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
|
||||
Reference in New Issue
Block a user