【问题标题】:Flutter- How to disable input form fieldFlutter-如何禁用输入表单字段
【发布时间】: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。

标签: dart flutter


【解决方案1】:

启用:假

使用它可以解决您的问题!

【讨论】:

    【解决方案2】:

    有时使用enabled : false 仍会导致文本字段在按下时聚焦。因此,您可以将其包裹在 IgnorePointer 周围作为替代方案。

    【讨论】:

      猜你喜欢
      • 2020-01-06
      • 2013-01-28
      • 2014-10-19
      • 1970-01-01
      • 1970-01-01
      • 2019-03-06
      • 2012-07-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多