Flutter- How to disable input form field

Viewed 5898

I am using TextFormField for entering mobile number which has the hint text as "Enter phone number",I want to place the prefix text(country code) when that text field comes to focus and hint text has to be hidden and prefix text has to be placed there (uneditable text).

Code:

 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,
);

}

2 Answers

enabled: false

using this will solve your problem!

Sometimes using enabled : false will still cause the textfield to be focused when press. So you can wrap it around a IgnorePointer as an alternative.

Related