skip to Main Content

I’m trying to figure out how to disable country selection using IntlPhoneField

I tried to pass in countries: country code, but it gives an error:
The element type ‘String’ can’t be assigned to the list type ‘Country’.

enter image description here

2

Answers


  1. You can add enabled : false to disable the field.
    there is other option like readOnly: true to disable user input.

    Login or Signup to reply.
  2. It accepts list of type Country.
    If you want to pass countries manually you should define countries like this.

    final countries = [Country(..name, flag)... ]
    

    Country model has been defined in the above package like this:

    class Country {
      final String name;
      final Map<String, String> nameTranslations;
      final String flag;
      final String code;
      final String dialCode;
      final String regionCode;
      final int minLength;
      final int maxLength;
    
      const Country({
        required this.name,
        required this.flag,
        required this.code,
        required this.dialCode,
        required this.nameTranslations,
        required this.minLength,
        required this.maxLength,
        this.regionCode = "",
      });
    

    If you don’t want to add countries by yourself, just don’t define the parameter countries.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search