skip to Main Content

I want to get full number from IntlPhoneField (package intl_phone_field )

I use controller to get number. but it not includes country code,

        IntlPhoneField(
                    disableLengthCheck: true,
                    controller: phoneNumberCon,
                    decoration: InputDecoration(
                      hintText: 'Phone Number',
                    ),
        ),

I tried,

            String input = phoneNumberCon.text.trim();
            String finalone = "${phone.countrycode} + $input";

It not working because phone.countrycode is not working.

2

Answers


  1. You can use onChanged method and try to pass out its value like this, First define new variable like this:

    String fullPhone = '';
    

    then try this:

    IntlPhoneField(
       disableLengthCheck: true,
       controller: phoneNumberCon,
       decoration: InputDecoration(
           hintText: 'Phone Number',
       ),
       onChanged: (phone) {
          print(phone.completeNumber);
          setState(() {
             fullPhone = phone.completeNumber;
          });
       },
    ),
    
    Login or Signup to reply.
  2. Have you checked the capitalisation required by the library?

    You have written:

    String finalone = "${phone.countrycode} + $input";
    

    Should it be this?

    String finalone = "${phone.countryCode} + $input";
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search