我有一个小部件,可以在小部件中添加一些装饰,如下所示。我还想更改小部件的装饰,例如删除TextFormField
小部件中的下划线。
class FormRowWidget extends StatelessWidget {
final Widget inputWidget;
FormRowWidget({this.title, this.inputWidget});
@override
Widget build(BuildContext context) {
var isTextField = inputWidget is TextFormField;
return Container(
padding: EdgeInsets.symmetric(horizontal: 8.0,vertical: 8.0),
decoration: BoxDecoration(
shape: BoxShape.rectangle,
color: Colors.white,
boxShadow: [
new BoxShadow(
color: Colors.black,
blurRadius: 10,
)
],
),
child: inputWidget// I want to change input widgets' properties.
])
}
}
我正在使用此小部件,如下面的代码。
children: <Widget>[
FormRowWidget(
inputWidget: TextFormField(
decoration: InputDecoration(border: InputBorder.none),
controller: usernameController,
validator: (value) {
if (value.length < 4) return "Username err!";
},
onSaved: (value) {
print(value);
},
),
),
FormRowWidget(
inputWidget: TextFormField(
decoration: InputDecoration(border: InputBorder.none),
controller: receiverFirmController,
),
)]
我想知道的是什么是重写inputWidget
中的FormRowWidget
的最好方法。
毕竟,我想像下面那样访问和更改小部件的设置。是否可以处理?
var customTextWidget = inputWidget as TextFormField;
customTextWidget.decoration