如何删除文本字段中图标和文本之间的间距 - Flutter?

How to remove spacing between Icon and text in textfield - Flutter?

我是 flutter 的新手,我正在创建一个搜索栏,为此,我使用了 TextField 并添加了前缀图标,但我在图标和图标之间得到了一些额外的 spaces输入文本。

请告诉我如何删除或减少 space?

下面是我的代码:

  child: TextField(
    decoration: InputDecoration(
      border: InputBorder.none,
      icon: IconButton(
        icon: Icon(Icons.search),
        color: Colors.pink,
        onPressed: () {},
      ),
    hintText: "Search for restaurant",
    hintStyle: TextStyle(fontSize: 15),
    onChanged: (input){
      print(input);
    },
  )

将此行添加到您的 Textfield

contentPadding: EdgeInsets.symmetric(vertical: -5),//set this as per your requirement 

您可以使用prefixIcon代替icon,默认情况下它不会占用文本和图标之间的space。

 TextField(
        decoration: InputDecoration(
          border: InputBorder.none,
          prefixIcon: IconButton(
            icon: Icon(
              Icons.search,
              color: Colors.pink,
            ),
            onPressed: () {},
          ),

          hintText: "Search for restaurant",
          hintStyle: TextStyle(fontSize: 15),
        ),
        onChanged: (input) {
          print(input);
        },
      ),