Move text editing Actions to EditableTextState (#90684)

This commit is contained in:
LongCatIsLooong
2021-11-03 11:11:32 -07:00
committed by GitHub
parent 035dfc87c5
commit ffcd32ebb6
24 changed files with 3403 additions and 3261 deletions

View File

@@ -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,