Flutter跨平台移动端开发丨TextField 添加背景色

TextField - decoration

打开 TextField 部件源码可见支持修改属性 decoration ,说明其支持样式会很丰富。本例演示怎样添加背景色

const TextField({

    // ··· 省略
    
    // 此对象可实现修改样式
    this.decoration = const InputDecoration(),  
    
    // ··· 省略
    
  }) : assert(textAlign != null),
       assert(autofocus != null),
       assert(obscureText != null),
       assert(autocorrect != null),
       assert(maxLengthEnforced != null),
       assert(scrollPadding != null),
       assert(dragStartBehavior != null),
       assert(maxLines == null || maxLines > 0),
       assert(maxLength == null || maxLength == TextField.noMaxLength || maxLength > 0),
       keyboardType = keyboardType ?? (maxLines == 1 ? TextInputType.text : TextInputType.multiline),
       super(key: key);

decoration - filled

设置背景色通过 decoration - filled + fillColor,filled 必须为 true

new Padding(
  padding: EdgeInsets.

猜你喜欢

转载自blog.csdn.net/qq_15609303/article/details/103099140