Flutter: how to avoid changing the keyboardType when using TextInputFormatter?

Viewed 143

When I change the newValue in my TextInputFormatter, the input method restart is automatically called. How can I avoid this? Message:

I/TextInputPlugin(26310): Composing region changed by the framework. Restarting the input method.

My formatter:

class GroupTextFormatter extends TextInputFormatter {
  @override
  TextEditingValue formatEditUpdate(
      TextEditingValue oldValue, TextEditingValue newValue) {
    String newText = newValue.text.toUpperCase();
    if (oldValue.text.length == 3 && newValue.text.length == 4) {
      newText += '-';
    } else if (oldValue.text.length == 6 && newValue.text.length == 7) {
      newText += '-';
    }

    return newValue.copyWith(
      text: newText,
      selection: TextSelection.collapsed(offset: newText.length),
    );
  }
}
0 Answers
Related