繁体   English   中英

如何删除 Flutter Widget 上 TextField 的背景颜色?

[英]How to remove background color of TextField on Flutter Widget?

我无法删除 TextField 的阴影和背景,这是我的代码:

TextFormField(
                            decoration: InputDecoration.collapsed(),
                            validator: (input) =>
                                input == "" ? 'The task is empty' : null,
                            onSaved: (input) => task = input,
                          )

这是我想要的结果

在此处输入图片说明

我总是尝试 BoxDecoration 但没有成功,因为不与 TextFormField 兼容。

您应该将填充设置为 true。

TextField(decoration: InputDecoration( fillColor: Colors.red, filled: true)),

将您的TextFormField包裹在Container并更改其color属性以匹配您的背景颜色(从您的图片中我会假设它是white ):

     Container(
        color: Colors.white, // or any color that matches your background
        child: TextFormField(
                 decoration: InputDecoration.collapsed(),
                 validator: (input) => input == "" ? 'The task is empty' : null,
                 onSaved: (input) => task = input,
               )
     ),

您可以通过将TextField包装在Theme小部件中并将splashColor设置为透明来使其透明

Theme(
  data: Theme.of(context).copyWith(splashColor: Colors.transparent),
  child: TextField(
    autofocus: false,
    style: TextStyle(fontSize: 22.0, color: Color(0xFFbdc6cf)),
    decoration: InputDecoration(
      filled: true,
      fillColor: Colors.white,
      hintText: 'Search',
    ),
  ),
);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM