【发布时间】:2019-04-01 15:56:27
【问题描述】:
我正在使用 TextFormField 输入提示文本为“输入电话号码”的手机号码,我想在该文本字段成为焦点时放置前缀文本(国家代码)并且必须隐藏提示文本并添加前缀文本必须放在那里(不可编辑的文本)。
代码:
Widget buildFields(
BuildContext context,
String hintTextValue,
TextEditingController fieldsController,
String paramName,
Function validateFields,
TextInputType type,
String prefixTextValue,
[inputFormatters]) {
valueBuilder = value != null ? value["primary_customer"][paramName] : null;
return TextFormField(
initialValue: valueBuilder,
onSaved: (text) {
fieldsController.text = text;
},
inputFormatters: [inputFormatters],
keyboardType: type,
decoration: InputDecoration(
hintText: hintTextValue,
prefixText: prefixTextValue,
prefixStyle: TextStyle(color: Colors.black)),
validator: validateFields,
);
}
【问题讨论】:
-
TextFormfield 有 enabled 属性,使用 make enabled: false。