flutter 如何修改TextField中的内容和光标高度

loc*_*clk 5 flutter flutter-layout

这张图中的光标和文字就是我想要的 在此输入图像描述

但我的演示是这样的。文本和光标很小并且没有填充

在此输入图像描述

代码

TextEditingController searchController = new TextEditingController();
FocusNode focusNode = new FocusNode();

// other code

TextField(
  key: Key("buy_subject_input"),
  autofocus: true,
  focusNode: focusNode,
  cursorColor: Colours.default_color,
  decoration: InputDecoration(
    hintText: 'search',
    hintStyle: TextStyle(
      color: Colours.hint_text_color,
    ),
    prefixIcon: Icon(
      Icons.search,
      color: Colours.hint_text_color,
    ),
    fillColor: Colors.white,
    filled: true,
    border: UnderlineInputBorder(
      borderSide: BorderSide.none,
      borderRadius: BorderRadius.all(Radius.circular(5)),
    ),
  ),
  controller: searchController,
),

//other code

Run Code Online (Sandbox Code Playgroud)

小智 6

 TextField(
  cursorHeight: 20, // you can put your ideal height here
  decoration: InputDecoration(
    border: OutlineInputBorder(),
    labelText: 'How to Change Cursor Height'
Run Code Online (Sandbox Code Playgroud)


小智 5

到处搜索后我终于发现你必须给出 style: TextStyle( height: 2.0, ) 来增加光标高度。

 TextField(
     style: TextStyle(
     height: 2.0,
     ),
     decoration: InputDecoration(
                    isDense: true,
                    contentPadding: EdgeInsets.only(
                        bottom: 15, top: 15, left: 10, right: 10)),
     ),
Run Code Online (Sandbox Code Playgroud)


Sam*_*dad 0

您可以使用CupertinoTextField来实现此目的:

CupertinoTextField(
  prefix: Icon(Icons.search),
  placeholder: 'search',
),
Run Code Online (Sandbox Code Playgroud)