Home > Blockchain >  get full phone number from intl_phone_field package
get full phone number from intl_phone_field package

Time:01-07

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.

CodePudding user response:

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

CodePudding user response:

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";
  • Related