flutter remove TextField default padding.md

需求

TextField 使用时有默认的padding,需要移除。

默认效果图

Still JPG (338x668).jpg

移除之后效果图

Still JPG (338x668).jpg

实现

使用InputDecoration,修改属性contentPaddingisDense

代码如下

class TextFieldRemovePaddingTest extends StatefulWidget {
  const TextFieldRemovePaddingTest({Key? key}) : super(key: key);

  @override
  State<StatefulWidget> createState() {
    return _TextFieldRemovePaddingTestState();
  }
}

class _TextFieldRemovePaddingTestState
    extends State<TextFieldRemovePaddingTest> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Center(
            child: Container(
      width: 200,
      color: Colors.blue,
      child: const TextField(
        style: TextStyle(
            fontSize: 14,
            height: 1,
            color: Color(0xFF303133),
            backgroundColor: Colors.green),
        decoration: InputDecoration(
            hintText: "please fill",
            contentPadding: EdgeInsets.symmetric(horizontal: 0, vertical: 0),
            isDense: true,
            border: InputBorder.none,
            hintStyle: TextStyle(
              color: Colors.black,
              height: 1,
              fontSize: 14,
            )),
      ),
    )));
  }
}

参考

https://stackoverflow.com/questions/59512321/cannot-remove-underside-padding-from-textfield-and-textformfield-in-flutter

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容