Flutter 修改源码禁用软键盘(PDA扫码适用)

Flutter 因为扫码输入经常弹出软键盘,造成键盘遮挡扫码框,所以需要对dart源码包进行修改,我通过查阅资料找到了相关文档,但是不全,没有修改代码的。所以只能一步一步进行试验。在经过很多次错误后,终于实现textFiled扫码不弹出软键盘。

以下为需要修改的文件的数据

1. text_input.dart

 修改后的方法

  (1)

  void show({bool needShow = true}) {//修改的此处

    assert(attached);

    TextInput._instance._show(needShow: needShow);//修改的此处

  }

(2)修改show方法

  void _show({bool needShow = true}) {//修改的此处

    assert(needShow);//修改的此处

    if (needShow) {//修改的此处

      _channel.invokeMethod<void>('TextInput.show');//修改的此处

    }

2.editable_text.dart

修改的方法

(1)2311行 修改方法

  void _openInputConnection() {

    if (!_shouldCreateInputConnection) {

      return;

    }

    if (!_hasInputConnection) {

      final TextEditingValue localValue = _value;



      // When _needsAutofill == true && currentAutofillScope == null, autofill

      // is allowed but saving the user input from the text field is

      // discouraged.

      //

      // In case the autofillScope changes from a non-null value to null, or

      // _needsAutofill changes to false from true, the platform needs to be

      // notified to exclude this field from the autofill context. So we need to

      // provide the autofillId.

      _textInputConnection = _needsAutofill && currentAutofillScope != null

          ? currentAutofillScope!

              .attach(this, _effectiveAutofillClient.textInputConfiguration)

          : TextInput.attach(

              this, _effectiveAutofillClient.textInputConfiguration);

      _updateSizeAndTransform();

      _updateComposingRectIfNeeded();

      _updateCaretRectIfNeeded();

      final TextStyle style = widget.style;

      _textInputConnection!

        ..setStyle(

          fontFamily: style.fontFamily,

          fontSize: style.fontSize,

          fontWeight: style.fontWeight,

          textDirection: _textDirection,

          textAlign: widget.textAlign,

        )

        ..setEditingState(localValue)

        ..show(needShow: needShow);//修改的此处

      if (_needsAutofill) {

        // Request autofill AFTER the size and the transform have been sent to

        // the platform text input plugin.

        _textInputConnection!.requestAutofill();

      }

      _lastKnownRemoteTextEditingValue = localValue;

    } else {

      _textInputConnection!.show(needShow: needShow);//修改的此处

    }

  }

(2)536行 EditableText类属性添加

this.needShow=true,//构造函数里添加

final bool needShow;//添加类属性

(3)EditableTextState类方法添加

 bool get needShow=>widget.needShow;

3 text_field.dart

(1)TextField 添加属性

this.needShow = true,//添加构造方法属性

final bool needShow;//添加属性

(2)_TextFieldState类添加获取方法

bool get needShow =>widget.needShow;//添加获取方法

(3)_TextFieldState build方法添加属性

   Widget child = RepaintBoundary(

      child: UnmanagedRestorationScope(

        bucket: bucket,

        child: EditableText(

          key: editableTextKey,

          needShow: needShow,//添加属性和方法

-----同理TextFormFiled也需要添加needShow属性

4. text_form_field.dart

(1)TextFormField添加属性

bool needShow = true,//添加构造方法属性

(2)返回方法添加


           

return UnmanagedRestorationScope(

              bucket: field.bucket,

              child: TextField(

                needShow: needShow,//添加属性

使用时 在textformField对象添加needShow属性

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值