Dinesh
Dinesh

Reputation: 1215

Flutter- How to disable input form field

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

}

Upvotes: 3

Views: 7588

Answers (2)

Mayb3Not
Mayb3Not

Reputation: 480

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.

Upvotes: 1

Fabio
Fabio

Reputation: 76

enabled: false

using this will solve your problem!

Upvotes: 6

Related Questions