Skip to content

Instantly share code, notes, and snippets.

@HansMuller
Created October 16, 2019 01:06
Show Gist options
  • Select an option

  • Save HansMuller/5d8b3573f446dafcb697da9f42206020 to your computer and use it in GitHub Desktop.

Select an option

Save HansMuller/5d8b3573f446dafcb697da9f42206020 to your computer and use it in GitHub Desktop.
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