Created
October 16, 2019 01:06
-
-
Save HansMuller/5d8b3573f446dafcb697da9f42206020 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:flutter/material.dart'; | |
| void main() { | |
| runApp(MaterialApp(home: MyHomePage())); | |
| } | |
| final TextEditingController controller = TextEditingController(); | |
| // It's possible to see the problem without using an EditableText subclass, | |
| // by just adding a print statement to _TextInputClientHandler in | |
| // packages/flutter/lib/src/services/text_input.dart under | |
| // case 'TextInputClient.updateEditingState'. | |
| class MyEditableText extends EditableText { | |
| MyEditableText() : super( | |
| // Commenting out this line causes updateEditingValue to be | |
| // called once per character, as expected. | |
| keyboardType: TextInputType.number, | |
| focusNode: FocusNode(), | |
| style: TextStyle(), | |
| cursorColor: Colors.red, | |
| backgroundCursorColor: Colors.green, | |
| controller: controller, | |
| ); | |
| @override | |
| MyEditableTextState createState() => MyEditableTextState(); | |
| } | |
| class MyEditableTextState extends EditableTextState { | |
| @override | |
| // When keyboardType is TextInputType.number this method | |
| // is called twice per input character. | |
| void updateEditingValue(TextEditingValue value) { | |
| print('updateEditingValue("${value.text}")'); | |
| super.updateEditingValue(value); | |
| } | |
| } | |
| class MyHomePage extends StatelessWidget { | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| body: Padding( | |
| padding: EdgeInsets.all(32), | |
| child: Container( | |
| color: Colors.blue.withOpacity(0.15), | |
| child: MyEditableText(), | |
| ), | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment