删除多行TextField右侧的滚动条- Flutter

vngu2lb8  于 2022-12-27  发布在  Flutter
关注(0)|答案(2)|浏览(145)

我在如下结构中有TextField purchaseCommentField()

@override
      Widget build(BuildContext context)
      {
        return GestureDetector(
          onTap: CommonUtils.endEditing(context),
          child: Container(
              width: _width,
              color: Colors.white,
              child: SingleChildScrollView(
                child: Column(
                  children: <Widget>[
                    ....
                    ...
                    Visibility(
                        visible: _additionalInfo != null,
                        child: purchaseCommentField()
                    ),
                    rowSpacer(16.0),
                    actionButton(context)
                  ],
                )
              )
          ),
        );
      }

 Widget purchaseCommentField()
  {
    return TextField(
      controller: _purchaseCommentController,
      minLines: 1,
      maxLines: null,
      keyboardType: TextInputType.multiline,
      style: new TextStyle(fontSize: 14.0),
      decoration: new InputDecoration(
        labelText: 'Additional Info',
        border: OutlineInputBorder(),
      ),
    );
  }

当我聚焦文本字段时,我在字段内得到了不需要的滚动条:

设置fontSize:14.0时出现此问题。删除此设置或将fontSize设置为16.0时,右侧没有滚动条:

有没有办法删除文本域中滚动条?

cbeh67ev

cbeh67ev1#

尝试使用TextFormField

TextFormField(
                      controller: textController,
                      validator: (value) {
                        if (value.trim().isEmpty) {
                          return _reportTypeModel.language.msgEnterDesc;
                        }
                        return null;
                      },
                      style: new TextStyle(fontSize: 14.0),
                      maxLength: 500,
                      decoration: InputDecoration(
                        labelText: _reportTypeModel.language.description,
                      ),
                      minLines: 4,
                      maxLines: 6,
                      keyboardType: TextInputType.multiline,
                      textInputAction: TextInputAction.next,
                    ),

输出:

7rtdyuoh

7rtdyuoh2#

github上有一个open issue与此相关,现在你可以通过创建一个定制的ScrollBehavior并覆盖buildScrollbar方法来修复这个问题:

class CustomScrollBehavior extends ScrollBehavior {
  const CustomScrollBehavior();

  @override
  Widget buildScrollbar(context, child, details) {
    return child;
  }
}

然后使用ScrollConfiguration小部件 Package TextField:

return ScrollConfiguration(
  behavior: const CustomScrollConfiguration(),
  child: TextField(
    // Your text-field params
  ),
);

这也适用于TextFormField

相关问题