Reputation: 1215
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
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