Flutter 移动应用退格键删除 2 个字符而不是 1 个

Flutter mobile app backspace delete 2 characters instead of 1

我有一个页面,当我点击按钮时会显示一个模态底部表。在 modalbottomsheet 中,它有一个 Pinput 字段,我可以在其中输入值。但是,当我按退格键时,它会删除 2 个字符而不是 1 个。有人知道它有什么问题吗,因为控制台没有显示任何内容。下面是 modalbottomsheet

的代码
_showCouponDetails(String coupon, bool couponStatus){
    int shopPinCode;
    int pinCode;
    final FocusNode _pinPutFocusNode = FocusNode();
    final TextEditingController _pinPutController = TextEditingController();

    return showModalBottomSheet(
        isScrollControlled: true,
        context: context,
        builder:(BuildContext context) =>
          GestureDetector(
            onTap: () {
              FocusScope.of(context).requestFocus(FocusNode());
            },
            child: Container(
                width: screenWidth,
                color: Colors.white,
                child: Column(
                  mainAxisSize: MainAxisSize.max,
                  mainAxisAlignment: MainAxisAlignment.start,
                  children: [
                    SizedBox(height: 24),
                    Padding(
                        padding: EdgeInsets.symmetric(horizontal: 10),
                        child: Text(coupon,
                                style: TextStyle(
                                  fontSize: 25,
                                  fontWeight: FontWeight.bold
                                )),
                        ),

                    couponStatus? Text(''):Image.asset('images/Redeemed.png', width: 100, height: 100),
                    Center(child:
                      Text('Expires on 31/12/2020')),
                    Container(
                      height: 100,
                      width: screenWidth*0.8,
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(15),
                        color: Colors.grey[200]
                      ),
                      child: Padding(
                        padding: EdgeInsets.all(10),
                        child: Center(
                          child: Column(
                            children: [
                              Text('Please ask the workshop to enter pin.'),
                              SizedBox(height: 10),
                              PinPut(
                                fieldsCount: 5,
                                focusNode: _pinPutFocusNode,
                                controller: _pinPutController,
                                eachFieldHeight: 30,
                              eachFieldWidth: 30,
                              selectedFieldDecoration: BoxDecoration(
                                border: Border.all(color: Colors.purple),
                                borderRadius: BorderRadius.circular(15)
                              ),
                              followingFieldDecoration: BoxDecoration(
                                  border: Border.all(color: Colors.purple),
                                  borderRadius: BorderRadius.circular(15),
                              ),
                              submittedFieldDecoration: BoxDecoration(
                                  border: Border.all(color: Colors.purple),
                                  borderRadius: BorderRadius.circular(15),
                              ),
                              onChanged: (_pinPutController){
                                  if (_pinPutController.isNotEmpty)
                                    pinCode = int.parse(_pinPutController);
                                    print (pinCode);
                                  },
                                ),
                            ]
                          )
                        ),
                      ),
                    ),
                    Spacer(),
                    Padding(
                      padding: EdgeInsets.all(10),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                        children: [
                          InkWell(
                            onTap: () {
                              
                            },
                            child: Container(
                              height: screenHeight*0.05,
                              width: screenWidth *0.4,
                              decoration: BoxDecoration(
                                  borderRadius: BorderRadius.circular(15),
                                  color: kPrimaryColor
                              ),
                              child: Center(child: Text('Redeem', style: TextStyle(fontWeight: FontWeight.bold,color: Colors.white, fontSize: 15))),
                            ),
                          ),
                          InkWell(
                            onTap: (){
                              Navigator.pop(context);
                            },
                            child: Container(
                              height: screenHeight*0.05,
                              width: screenWidth *0.4,
                              decoration: BoxDecoration(
                                borderRadius: BorderRadius.circular(15),
                                border: Border.all(color: Colors.black),
                                color: Colors.white
                              ),
                              child: Center(child: Text('Cancel', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15))),
                            ),
                          ),
                        ],
                      ),
                    )
                  ],
                ),
              ),
          ),
      );
  }

更新:包括图片。在图片中,我输入了 1,2 和 3。每当我按退格键时,它都会删除 2 和 3(图片 2)。图3中,控制台打印了两次数字。

你说的是数字框内的数字加号和退格吗?好吧,这在我的编译过程中工作正常。如果没有,您能否添加问题的屏幕截图。

我通过更改 flutter 频道解决了这个问题。我使用的是 flutter channel beta,显然这个退格键是一个错误。切换到 flutter channel stable 后一切正常

要检查你的 flutter 频道,请在终端中输入以下内容 颤动--版本

要更改 flutter 通道,请在终端中键入以下内容 颤振频道大师