intl_phone_number_input
intl_phone_number_input copied to clipboard
validation not working
How can you check if the number is not empty, been scratching my head for days. The error is not displayed
IntlPhoneField(
autovalidateMode: AutovalidateMode.onUserInteraction,
decoration: InputDecoration(
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(60),
borderSide: BorderSide(
width: 1.0,
style: BorderStyle.solid,
color: WAPrimaryColor),
),
),
inputFormatters: [
FilteringTextInputFormatter.allow(
RegExp("[0-9]"))],
validator: (value) {
if (value == null) {
return 'Please enter your Phone Number';
}
return null;
},
initialCountryCode: 'NG',
keyboardType: TextInputType.number,
onChanged: (value) {
phonenumber = value.number;
},
),
this doesn't work, i is ignored
Validator passes a String? not a dynamic value. So you should check value.isNotEmpty or value.isEmpty
validator: (phoneNumber) { if (phoneNumber!.isEmpty) { return 'Phone Number Required'; } return null; },