Android 设备上的退格键文本字段抖动无法正常工作

Log*_*ogy 5 dart flutter flutter-test flutter-layout

当我在文本上退格,然后再次键入时,键入内容不会显示在文本字段中,并且退格本身也不起作用。我不知道是颤振本身的问题还是什么,因为很多人都有同样的问题。

                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),
                    ),
                  ),
                ),
Run Code Online (Sandbox Code Playgroud)

ras*_*maz -1

屏蔽文本输入格式化程序

  • 创建格式化程序

var maskFormatter = MaskTextInputFormatter(mask: '####-####', 过滤器: {"#": RegExp(r'[0-9]')}, type: MaskAutoCompletionType.eager);

  • 并添加您的 TextField 格式化程序

    TextField(
                    controller: controller,
                    maxLength: 9,
                    keyboardType: TextInputType.text,
                    textCapitalization: TextCapitalization.characters,
                    // here -> 
                    inputFormatters: [maskFormatter],
                    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),
                      ),
                    ),
                  ),
    
    Run Code Online (Sandbox Code Playgroud)
  • 终于拿到数据了

maskFormatter.getMaskedText();

maskFormatter.getUnmaskedText();
Run Code Online (Sandbox Code Playgroud)