Search code examples
flutterdartflutter-dependencies

get full phone number from intl_phone_field package


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.


Solution

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