在我的自定义表单字段中,我想获取应用程序的默认fillColor并在自定义控件中使用它。正确的方法是什么?以下方法返回null,即使默认TextFormField填充为灰色。
class CustomFormField extends FormField<String> {
CustomFormField({
String? initialText,
FormFieldSetter<String>? onSaved,
FormFieldValidator<String>? validator,
AutovalidateMode? autovalidateMode,
Key? key,
}) : super(
onSaved: onSaved,
validator: validator,
initialValue: initialText,
autovalidateMode: autovalidateMode,
key: key,
builder: (FormFieldState<String> state) {
var fillColor =
Theme.of(state.context).inputDecorationTheme.fillColor;
// ISSUE: fillColor is null, even though the default
// TextFormField fills with a shade of grey in the same app.
return Container(
// with custom control UI using fillColor
);
},
);
}
1条答案
按热度按时间ljsrvy3e1#
我通过在应用初始化时在应用级别显式设置inputDecorationTheme来实现这一点。