the_country_number

Creator: coderz1093

Last updated:

Add to Cart

Description:

the country number

the_country_number #
A small library for flutter written in pure dart (doesn't use libphonenumber) which parses a phone number or iso2 code of a country to give you some vitals about the country (thanks for everyone who contributed to the data here)
go here for a flutter input widget which is based on this
use version 0.9.0 to skip nullsafety
this library is a singleton so you can use the library right-away
final theNumber = TheCountryNumber().parse();
copied to clipboard
if you have the complete international number as string
//a united arab emirates number
final _numberString = "+971565656565";
final theNumber = TheCountryNumber().parse(internationalNumber:_numberString);
print(theNumber.dialCode);//prints +971
print(theNumber.number);//prints 565656565
copied to clipboard
further the parsed number contains a TheCountry object which provides some useful vitals
final country = theNumber.country;
print(country.englishName);//prints United Arab Emirates
print(country.localName);//prints دولة الإمارات العربية المتحدة (hope spelling is correct)
print(country.currency);//prints AED
//etc
copied to clipboard
you can parse TheNumber with other properties as well, but the number component will be missing
final theNumber = TheCountryNumber().parseNumber(iso2Code: "IN");
print(theNumber.dialCode);//prints the international dial-code for this country "+91"
print(theNumber.number); //prints empty
//access country details
final country = theNumber.country;
print(country.englishName);//prints India
print(country.localName);//prints भारत (hope spelling is correct)
print(country.currency);//prints INR
copied to clipboard
further you can parse realtime in flutter on input data changed
final numberWithCountryDetails = TheCountryNumber().parse(iso2Code:"AE");
//parse realtime when data is available
onChanged(s){
///consider s = "565656565";
if(s.isEmpty()){
return;
}
final newNumber = numberWithCountryDetails.addNumber(s);
//check if the length is valid for the given country
if(newNumber.isValidLength){
//do something
print(newNumber.dialCode);//prints +971
print(newNumber.internationalNumber);//prints +971565656565
}
}
copied to clipboard
A NotANumber object will be returned if failed to parse, you can check if the return Object is not a number
final theSupposedNumber = TheCountryNumber().parse(iso2Code:"xxxxxx");
if(theSupposedNumber.isNotANumber){
//cancel operation
return;
}
copied to clipboard
keep in mind that some countries support phone numbers of multiple lengths, which is supported too
Note: This license has also been called the "New BSD License" or "Modified BSD License". See also the 2-clause BSD License.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:


Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.


Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.


Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.


THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Copyright 2020 www.yadunandan.xyz
sponsored by www.bigmints.com #

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.