This is the monorepo containing all of the related packages for flutter_libphonenumber
.
We use melos
to manage the packages.
$ flutter pub get
$ flutter pub run melos bootstrap
Leverages libphonenumber to allow for asynchronous and synchronous formatting of phone numbers in Flutter apps. Includes a TextInputFormatter to allow real-time AsYouType formatting.
License: MIT License
Hi,
I can add succesfully the library doing flutter pub add flutter_libphonenumber
. flutter pub get
after 'flutter clean' work as well. But when I run the project for android in VS code, I get the following error:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':flutter_libphonenumber_android'.
> Could not resolve all files for configuration ':flutter_libphonenumber_android:classpath'.
> Could not resolve org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.0.
Required by:
project :flutter_libphonenumber_android > com.android.tools.build:gradle:7.1.2
project :flutter_libphonenumber_android > com.android.tools.build:gradle:7.1.2 > com.android.tools:sdk-common:30.1.2
project :flutter_libphonenumber_android > com.android.tools.build:gradle:7.1.2 > com.android.tools:repository:30.1.2
project :flutter_libphonenumber_android > com.android.tools.build:gradle:7.1.2 > com.android.tools.ddms:ddmlib:30.1.2
project :flutter_libphonenumber_android > com.android.tools.build:gradle:7.1.2 > com.android.tools.build:aaptcompiler:7.1.2
project :flutter_libphonenumber_android > com.android.tools.build:gradle:7.1.2 > com.android.tools.analytics-library:shared:30.1.2
project :flutter_libphonenumber_android > com.android.tools.build:gradle:7.1.2 > com.android.tools.lint:lint-model:30.1.2
project :flutter_libphonenumber_android > com.android.tools.build:gradle:7.1.2 > androidx.databinding:databinding-compiler-common:7.1.2
project :flutter_libphonenumber_android > com.android.tools.build:gradle:7.1.2 > com.android.tools.utp:android-test-plugin-host-retention-proto:30.1.2
project :flutter_libphonenumber_android > com.android.tools.build:gradle:7.1.2 > org.jetbrains.dokka:dokka-core:1.4.32
project :flutter_libphonenumber_android > com.android.tools.build:gradle:7.1.2 > com.android.tools.build:builder:7.1.2
project :flutter_libphonenumber_android > com.android.tools.build:gradle:7.1.2 > com.android.tools.build:builder-model:7.1.2
project :flutter_libphonenumber_android > com.android.tools.build:gradle:7.1.2 > com.android.tools.build:gradle-api:7.1.2
project :flutter_libphonenumber_android > com.android.tools.build:gradle:7.1.2 > com.android.tools:sdk-common:30.1.2 > com.android.tools:common:30.1.2
project :flutter_libphonenumber_android > com.android.tools.build:gradle:7.1.2 > com.android.tools.build:builder:7.1.2 > com.android.tools.analytics-library:tracker:30.1.2
project :flutter_libphonenumber_android > com.android.tools.build:gradle:7.1.2 > com.android.tools.build:builder:7.1.2 > com.android.tools.build:manifest-merger:30.1.2
flutter_libphonenumber: ^1.2.4
When parsing a number with no regionCode, for example 01114377479 (An Egyptian number), sometimes it returns +201114377479, other times it fails to parse. Why would there be this inconsistency, how can i help?
We are using this library in two different projects, applying masks for brazilian phone numbers.
The first one is using version 1.1.0 and the second started using this lib with version 1.2.1.
We notice that the mask is not being applied correctly in version 1.2.1.
With 1.1.0, the correct mask is: +55 (XX) XXXXX-XXXX
With 1.2.1, the wrong mask is +55 XXXXX-XXXX
We had to downgrade to version 1.1.0 in both projects.
Tested only in iOS, with latest Flutter version (stable).
I'm trying to show a list of countries with phone numbers in some locale but can't do this. Library get country name in system locale. It is possible to change it?
Hello, This is My TextField
TextField(
keyboardType: TextInputType.phone,
controller: textEdtControllerMobileNumber,
autofocus: true,
inputFormatters: [
LibPhonenumberTextFormatter(
phoneNumberType: globalPhoneType,
phoneNumberFormat: globalPhoneFormat,
country: countryWithPhonenum,
hideCountryCode: true,
additionalDigits: 3,
),
],
))
The problem is when I input the number in the TextField, let's say 123456789 then I want to remove the number 3 when I take the cursor after number 3 and remove it the cursor will be automatically goes to the end of the number after 9 instead of it should keep it cursor position after 2.
I hope I explained the issue well.
Error:
MissingPluginException(No implementation found for method parse on channel flutter_libphonenumber)
Running into this issue which I see people have reported in the past, however I'm experiencing it while running tests and the app itself works fine.
Using VS Code if that changes anything.
[✗] Android toolchain - develop for Android devices
✗ Unable to locate Android SDK.
Install Android Studio from: https://developer.android.com/studio/index.html
On first launch it will assist you in installing the Android SDK components.
(or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).
If the Android SDK has been installed to a custom location, please use
flutter config --android-sdk
to update to that location.
[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 14B47b
• CocoaPods version 1.11.3
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[!] Android Studio (not installed)
• Android Studio not found; download from https://developer.android.com/studio/index.html
(or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).
[✓] VS Code (version 1.74.3)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.58.0
[✓] Connected device (3 available)
• iPhone 14 (mobile) • 9CD70026-7E08-4947-A071-601C41106272 • ios • com.apple.CoreSimulator.SimRuntime.iOS-16-1 (simulator)
• macOS (desktop) • macos • darwin-arm64 • macOS 12.6 21G115 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 109.0.5414.119
[✓] HTTP Host Availability
• All required HTTP hosts are available
! Doctor found issues in 2 categories.
Formatting the number "+642101234567" using "formatNumberSync" produces the output "+64 21 012 3456"
It should not drop any digits from the end. The expected output is
"+64 21 012 34567"
Testing using libphonenumber.appspot produces the correct output:
https://libphonenumber.appspot.com/phonenumberparser?number=%2B642101234567
Calling this text formatter:
LibPhonenumberTextFormatter( country: usCountry, PhoneNumberFormat.national)
Will result in the following mask "0) 000-0000"
It should be "(000) 000-0000"
There are a couple problems:
input_formatter.dart line 28: removeCountryCodeFromMask gets set to true even though the phone number is a national number and the inputContainsCountryCode is false.
Once removeCountryCodeFromMask is true country_data.dart line 188 will remove three characters from the beginning of the national mask therefore chopping off the area code portion of the national phone number mask.
Some valid Malaysian mobile phone numbers start with 6011 and contains 12 digits such as 6011-1234-5678. This library does not recognise such numbers.
Please push you docs to pub.dev so the
pod "PhoneNumberKit", :git => "https://github.com/marmelroy/PhoneNumberKit"
is removed from the pub.dev site
I use the formatNumberSync
method for the formatter and for the phone number +359888134485 it does not return the last digit "5": +359 88 813 448. At the same time, when checking the number +359888134485 through the parse
method, this method returns a Map with the "international" property = + 359 88 813 4485, which is the correct value. Can you fix the formatNumberSync
method?
libphonenumber.min.js:7 Uncaught TypeError: Cannot set properties of null (setting 'exports')
at libphonenumber.min.js:7:87
at libphonenumber.min.js:7:330
(anonymous) @ libphonenumber.min.js:7
(anonymous) @ libphonenumber.min.js:7
flutter_libphonenumber_web.dart:73 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'PhoneNumberUtil')
at getAllSupportedRegions (flutter_libphonenumber_web.dart:73:44)
at getAllSupportedRegions.next (<anonymous>)
at async_patch.dart:45:50
at _RootZone.runUnary (zone.dart:1661:54)
at _FutureListener.thenAwait.handleValue (future_impl.dart:147:18)
at handleValueCallback (future_impl.dart:784:44)
at _Future._propagateToListeners (future_impl.dart:813:13)
at async._AsyncCallbackEntry.new.callback (future_impl.dart:448:9)
at Object._microtaskLoop (schedule_microtask.dart:40:11)
at _startMicrotaskLoop (schedule_microtask.dart:49:5)
at async_patch.dart:177:15
when entering an italian number it returns "vatikanstadt" instead of italy as detected country.
Is this the expected behaviour or how can I get Italy as the country of origin ?
I believe this is the same thing that was happening on a previous issue:
[!] CocoaPods could not find compatible versions for pod "PhoneNumberKit/PhoneNumberKitCore":
In Podfile:
PhoneNumberKit (from https://github.com/marmelroy/PhoneNumberKit
) was resolved to 3.7.3, which depends on
PhoneNumberKit/PhoneNumberKitCore (= 3.7.3)
flutter_libphonenumber_ios (from `.symlinks/plugins/flutter_libphonenumber_ios/ios`) was resolved to 1.1.4, which depends on
PhoneNumberKit/PhoneNumberKitCore (= 3.6.6)
Specs satisfying the PhoneNumberKit/PhoneNumberKitCore (= 3.7.3), PhoneNumberKit/PhoneNumberKitCore (= 3.6.6)
dependency were found, but they required a higher minimum deployment target.
Pod install error with this plugin
i try to add git to pod file
pod 'PhoneNumberKit', :git => 'https://github.com/marmelroy/PhoneNumberKit'
[!] CocoaPods could not find compatible versions for pod "PhoneNumberKit/PhoneNumberKitCore":
In Podfile:
PhoneNumberKit (from `https://github.com/marmelroy/PhoneNumberKit`) was resolved to 3.6.6, which depends on
PhoneNumberKit/PhoneNumberKitCore (= 3.6.6)
flutter_libphonenumber_ios (from `.symlinks/plugins/flutter_libphonenumber_ios/ios`) was resolved to 1.1.0, which depends on
PhoneNumberKit/PhoneNumberKitCore (= 3.5.10)
Specs satisfying the `PhoneNumberKit/PhoneNumberKitCore (= 3.5.10), PhoneNumberKit/PhoneNumberKitCore (= 3.6.6)` dependency were found, but they required a higher minimum deployment target.
MissingPluginException(No implementation found for method isValidPhoneNumber on channel codeheadlabs.com/libphonenumber)
All ORANGE cell phone numbers after the country code (+225) now start with 07
All MTN cell phone numbers after the country code (+225) now start with 05
All MOOV cell phone numbers after the country code (+225) now start with 01
Can we have this fixed please?
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.10.3, on macOS 13.4 22F66 darwin-arm64, locale en-MY)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 14.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.2)
[✓] VS Code (version 1.78.2)
[✓] Connected device (2 available)
[✓] Network resources
• No issues found!
flutter_libphonenumber: ^2.1.3
pod update
without errorpod update
Specs satisfying the `PhoneNumberKit/PhoneNumberKitCore (= 3.6.0),
PhoneNumberKit/PhoneNumberKitCore (= 3.5.10)` dependency were found,
but they required a higher minimum deployment target.
when entering an austrian mobile number there is one digit missing.
for example the number is 664 1234567
but the inputformatter stops at 664 123456
I think it is the same problem as in #4 with a different country
Hi,
I have tried using your lib to parse and format numbers, especially french national number.
I want to parse this number '06 06 06 06 06' with the region 'FR', and I'm expecting to get a valid parsing, corresponding to the international number '+33 6 06 06 06 06'. But I get an exception : PlatformException(InvalidNumber, Number +06 06 06 06 06 is invalid, null, null).
I have checked on this LibPhoneNumber demo : https://libphonenumber.appspot.com/ and I have tested it in an Android project with the native lib and it works fine.
I guess the problem is that you add a leading '+' with the method _ensureLeadingPlus(phone) before using the native library methods. In the case of french numbers, '0606060606' is a valid national number, but '+0606060606' isn't.
Hello,
There was some phone number changes in multiple countries (especially Ivory Coast). On Android side for example this is the commit updating the metadata.
Could you please update this library to use the latest Android and iOS libraries please ? :)
PhoneNumberUtil.isValidPhoneNumber for Netherlands (+31) is returning invalid for valid numbers.
Getting the below error in iOS
error: compiling for iOS 8.0, but module 'PhoneNumberKit' has a minimum deployment target of iOS 9.0: .....PhoneNumberKit/PhoneNumberKit.framework/Modules/PhoneNumberKit.swiftmodule/arm64-apple-ios.swiftmodule
import PhoneNumberKit
^
When LibPhonenumberTextFormatter is used and for example +1 entered, it will detect Puerto Rico as a country. Canada and United States have the same.
It would be useful to get these based on area code: https://stackoverflow.com/questions/34404231/google-libphone-number-for-getting-country-name-for-the-same-country-code
Is it possible to add a callback, when the full mask is matched? So that we could have an error state till it is a full number?
Some countries have multiple mobile formats. Austria and Bulgaria for example.
+43 6604 856532
+43 6604 85653
Validation | Results |
---|---|
Result from isPossibleNumber() | true |
Result from isValidNumber() | true |
Phone Number region | AT |
Result from getNumberType() | MOBILE |
If I override the phone format, the one with fewer digits is detected as an invalid format. Any idea how can I support both formats?
await FlutterLibphonenumber().init(overrides: {
'AT': CountryWithPhoneCode(
phoneCode: '43',
countryCode: 'AT',
exampleNumberMobileNational: '06643 123456',
exampleNumberFixedLineNational: '01 234567890',
phoneMaskMobileNational: '00000 000000',
phoneMaskFixedLineNational: '00 000000000',
exampleNumberMobileInternational: '+43 6643 123456',
exampleNumberFixedLineInternational: '+359 2 123 4567',
phoneMaskMobileInternational: '+00 0000 000000',
phoneMaskFixedLineInternational: '+00 0 000000000',
countryName: 'Austria',
)
});
I was using CountryManager().deviceLocaleCountryCode, but since I moved to 1.x to enable null safety, this var does not exist anymore. Why? It's was useful for selecting the default country of the user.
final sortedCountries = CountryManager().countries
..sort((a, b) => (a.countryName ?? '')
.compareTo(b.countryName ?? ''));
As mentioned in the demo above statement return 0.
[!] CocoaPods could not find compatible versions for pod "PhoneNumberKit/PhoneNumberKitCore":
In Podfile:
PhoneNumberKit (from https://github.com/marmelroy/PhoneNumberKit
) was resolved to 3.5.10, which depends on
PhoneNumberKit/PhoneNumberKitCore (= 3.5.10)
flutter_libphonenumber_ios (from `.symlinks/plugins/flutter_libphonenumber_ios/ios`) was resolved to 1.1.0, which depends on
PhoneNumberKit/PhoneNumberKitCore (= 3.5.9)
Specs satisfying the PhoneNumberKit/PhoneNumberKitCore (= 3.5.10), PhoneNumberKit/PhoneNumberKitCore (= 3.5.9)
dependency were found, but they required a higher minimum deployment target.
Hi,
I've followed the instructions in the README. Using:
Flutter 1.22.4
sdk: ">=2.7.0 <3.0.0"
flutter_libphonenumber: ^0.3.11
I have initialized the package via:
FlutterLibphonenumber().init();
Then after the value is provided, I do:
final res = await FlutterLibphonenumber().parse(value);
The last code throws the following exception:
MissingPluginException(No implementation found for method parse on channel flutter_libphonenumber)
Any idea on what could be going wrong?
flutter_libphonenumber: ^2.2.1
[!] CocoaPods could not find compatible versions for pod "flutter_libphonenumber_ios":
In Podfile:
flutter_libphonenumber_ios (from .symlinks/plugins/flutter_libphonenumber_ios/ios
)
Specs satisfying the flutter_libphonenumber_ios (from
.symlinks/plugins/flutter_libphonenumber_ios/ios)
dependency were found, but they required a higher minimum deployment target.
Error while running Gradle task 'assembleDebug'...
FAILURE: Build failed with an exception.
'compileDebugJavaWithJavac' task (current target is 1.8) and 'compileDebugKotlin' task (current target is 17) jvm target compatibility should be set to the same Java version.
On a flutter iOS app I'm running into issues after someone changes from the default option (UK) and then back to it, the uk mask is inconsistent.
I have two text boxes with the following [+44] [rest of number]. And the following formatter:
LibPhonenumberTextFormatter(
phoneNumberType: PhoneNumberType.mobile,
phoneNumberFormat: PhoneNumberFormat.national,
country: _currentlySelectedCountry,
inputContainsCountryCode: false)
This will work fine for the first number. If I then change it from GB -> US -> GB using the country drop down if I type in a number you will only be able to type in half. I.e the formatter allows only "0 000000".
If I change inputContainsCountryCode
to true. Then the default GB requires you to enter the country code in the second box and the country GB doesn't.
The issue seem to stem from the fact that phoneMaskMobileNational
is different between the two responses. This means that the LibPhonenumberTextFormatter
can't work in a consistent way between the two options.
LibPhonenumberTextFormatter(
phoneNumberType: PhoneNumberType.mobile,
phoneNumberFormat: PhoneNumberFormat.national,
country: _currentlySelectedCountry,
inputContainsCountryCode: true,
CountryWithPhoneCode.gb()
gives the following:
CountryWithPhoneCode(countryName: United Kingdom, regionCode: GB, phoneCode: 44, exampleNumberMobileNational: 07400 123456, exampleNumberFixedLineNational: 0121 234 5678, phoneMaskMobileNational: 00000 000000, phoneMaskFixedLineNational: 0000 000 0000, exampleNumberMobileInternational: +44 7400 123456, exampleNumberFixedLineInternational: +44 121 234 5678, phoneMaskMobileInternational: +00 0000 000000, phoneMaskFixedLineInternational: +00 000 000 0000)
From the countries list I get this:
CountryWithPhoneCode(countryName: United Kingdom, regionCode: GB, phoneCode: 44, exampleNumberMobileNational: 07400 123456, exampleNumberFixedLineNational: 0121 234 5678, phoneMaskMobileNational: +00 00000 000000, phoneMaskFixedLineNational: +00 0000 000 0000, exampleNumberMobileInternational: +44 7400 123456, exampleNumberFixedLineInternational: +44 121 234 5678, phoneMaskMobileInternational: +00 0000 000000, phoneMaskFixedLineInternational: +00 000 000 0000)
+9779861eeeeee this number seems sure invalid. However, if passed to ,
await PhoneNumberUtil.isValidPhoneNumber(
phoneNumber: phone,
isoCode: selectedCountryCode.code!,
);
is return true because the length exactly matches. Thank you for the package though.
Hello,
I'm currently searching a library to handle the phone number changes in Ivory coast (details here: link ).
I'm trying to test this library by running the example and see if everything is working as expected and unfortunately it's not. The test I'm running is the following :
import "package:test/test.dart";
import 'package:flutter_libphonenumber/flutter_libphonenumber.dart';
void main() {
group('flutter_libphonenumber library testing', () {
setUpAll(() async {
await FlutterLibphonenumber().init();
});
test(
'should parse phonenumber',
() {
final rawNumber = '+14145556666';
final formattedNumber =
FlutterLibphonenumber().formatNumberSync(rawNumber);
expect(formattedNumber, "+1 414-555-6666");
},
);
});
}
And the output is the following :
Expected: '+1 414-555-6666'
Actual: '14145556666'
Which: is different.
Expected: +1 414-555 ...
Actual: 1414555666 ...
^
Differ at offset 0
Is this a bug or am I doing something wrong ? Thank you in advance for the help !
I have a Flutter project and its Android project is running with the following configuration:
After upgrading my Android Studio to Flamingo 2022.2.1 Patch 1, I had to point the Java home to the internal one inside Android Studio, which is jbr17. Then I had to upgrade the Android project to target Java 17 like below:
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '17'
}
}
Afterwards I had a build error with the flutter_libphonenumber_android module:
Execution failed for task ':flutter_libphonenumber_android:compileDebugKotlin'.
> 'compileDebugJavaWithJavac' task (current target is 1.8) and 'compileDebugKotlin' task (current target is 17) jvm target compatibility should be set to the same Java version.
Consider using JVM toolchain: https://kotl.in/gradle/jvm/toolchain
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
So I guess the flutter_libphonenumber_android
module needs an upgrade to be able to run with the latest Android build tool. For now, to overcome the issue, I had to work around like below in the root build file of my Android module:
project(':flutter_libphonenumber_android').afterEvaluate {
project(':flutter_libphonenumber_android').android {
compileSdkVersion 30
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '17'
}
}
}
Parse method does not work on 16.4.1 iOS getting this error:
Domain=NSCocoaErrorDomain Code=4099 "The connection to service with pid 1119 named com.apple.commcenter.coretelephony.xpc was invalidated from this process." UserInfo={NSDebugDescription=The connection to service with pid 1119 named com.apple.commcenter.coretelephony.xpc was invalidated from this process.}
I've tested the same build on iOS 16.4.0 and the plugin works fine.
I've just found your lib and I would like to use it, but what I need more is that the phone format works for Brazil's phone number.
In Brasil we have 2 different types of format numbers +55 (xx) xxxx-xxxx [for residential numbers] and +55 (xx) xxxxx-xxxx [for cellphones].
Your solution only works for residential numbers, but what we really need is that it works for cellphone numbers. It would be really helpful if you could fix that!
"As established by ANATEL, the Brazilian federal telecommunications regulatory agency, the format for a local phone number is nnnn-nnnn (eight digits) for landlines, and nnnnn-nnnn (nine digits) for mobile lines."
https://en.wikipedia.org/wiki/Telephone_numbers_in_Brazil
Thanks a lot!
Hi!
I'm a main contributor of flutter-form-builder-ecosystem that currently include the package phone_number.
I really want improve the maintain of phone_number, but is too hard to me alone.
We can join efforts to made a nice package to format, validate and other things with phone numbers. Take a look on this comment to more details natintosh/intl_phone_number_input#201 (comment)
Best regards
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.