Flutter - International Phone Field - Check Max Length of Phone Number of Related Country

Viewed 1502

I added intl_phone_field to my flutter application. It works perfectly. I used 2.0.1 version.

I wrote like this;

IntlPhoneField(
                      decoration: InputDecoration(
                        labelText: "Phone Number",
                        labelStyle: TextStyle(
                          fontSize: 14.0,
                        ),
                        hintStyle: TextStyle(
                          color: Colors.grey,
                          fontSize: 10.0,
                        ),
                      ),
                      initialCountryCode: 'US', //default country code
                      onChanged: (phone) {
                        //when phone number country code is changed
                        print(phone.completeNumber); //get complete number
                        print(phone.countryCode); // get country code only
                        print(phone.number); // only phone number
                      },),

It seems like this picture below. As their devs mentioned on changelog, they added maximum length of phone numbers of several countries. So as I showed with red arrow on my picture below, there is a length field.

phone number

The phone number length depends on every country. So my question is, for example for this picture, how can I check that 10/10 numbers character entered?

1 Answers

it's a bit tricky to access this value, but you can: Start by importing this file in addition to intl_phone_field.dart:

import 'package:intl_phone_field/countries.dart';

And then:

IntlPhoneField(
                  ...
                  onChanged: (phone) {
                    print(countries.firstWhere((element) => element['code'] == phone.countryISOCode)['max_length']);
                  },
),
Related