'backspace text field flutter on Android devices not working

when I do backspacing on a text, and then type again, the typing does not show up in the text field and the backspacing itself doesn't work good. I don't know if the problem is with the flutter itself or what because many people have the same issue.

                TextField(
                  controller: controller,
                  maxLength: 9,
                  keyboardType: TextInputType.text,
                  textCapitalization: TextCapitalization.characters,

                  onChanged: (text) {
                    if (7 > pin.length) {
                      final String newText = _addDashes(text);
                      controller.text = newText;
                      controller.selection =
                          TextSelection.collapsed(offset: newText.length);
                    }

                    pin = text;
                  },
                  textAlign: TextAlign.left,
                  // keyboardType: TextInputType.visiblePassword,
                  decoration: InputDecoration(
                    errorText: _errorText,
                    icon: Icon(
                      Icons.dialpad,
                    ),
                    labelText: '8-digit PIN',
                    contentPadding: EdgeInsets.symmetric(vertical: 10.0),
                    focusedBorder: UnderlineInputBorder(
                      borderSide:
                          BorderSide(color: Colors.transparent, width: 2),
                    ),
                    focusedErrorBorder: UnderlineInputBorder(
                      borderSide: BorderSide(color: Colors.red, width: 2),
                    ),
                    errorBorder: UnderlineInputBorder(
                      borderSide:
                          BorderSide(color: Color(0xFFF696969), width: 1),
                    ),
                  ),
                ),


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source