diff --git a/libphonenumber_platform_interface/.idea/libraries/Dart_Packages.xml b/libphonenumber_platform_interface/.idea/libraries/Dart_Packages.xml
index 7441ace..1e3bd87 100644
--- a/libphonenumber_platform_interface/.idea/libraries/Dart_Packages.xml
+++ b/libphonenumber_platform_interface/.idea/libraries/Dart_Packages.xml
@@ -5,182 +5,174 @@
-
+
-
+
-
-
-
-
-
-
-
-
+
-
+
-
+
-
+
-
+
-
+
-
+
+
+
+
+
+
+
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
-
-
-
-
-
-
-
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/libphonenumber_platform_interface/.idea/libraries/Dart_SDK.xml b/libphonenumber_platform_interface/.idea/libraries/Dart_SDK.xml
index e450131..41e82d7 100644
--- a/libphonenumber_platform_interface/.idea/libraries/Dart_SDK.xml
+++ b/libphonenumber_platform_interface/.idea/libraries/Dart_SDK.xml
@@ -1,26 +1,25 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/libphonenumber_platform_interface/.idea/workspace.xml b/libphonenumber_platform_interface/.idea/workspace.xml
index 285a965..dd5f91d 100644
--- a/libphonenumber_platform_interface/.idea/workspace.xml
+++ b/libphonenumber_platform_interface/.idea/workspace.xml
@@ -1,5 +1,8 @@
+
+
+
@@ -21,16 +24,12 @@
-
-
-
-
-
-
-
+
+
+
+
-
@@ -40,6 +39,9 @@
+
+
+
@@ -49,12 +51,15 @@
+
+
+
@@ -78,7 +83,6 @@
-
diff --git a/libphonenumber_platform_interface/pubspec.lock b/libphonenumber_platform_interface/pubspec.lock
index d3c3392..805f1ae 100644
--- a/libphonenumber_platform_interface/pubspec.lock
+++ b/libphonenumber_platform_interface/pubspec.lock
@@ -7,7 +7,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
- version: "2.8.1"
+ version: "2.9.0"
boolean_selector:
dependency: transitive
description:
@@ -21,35 +21,28 @@ packages:
name: characters
url: "https://pub.dartlang.org"
source: hosted
- version: "1.1.0"
- charcode:
- dependency: transitive
- description:
- name: charcode
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.3.1"
+ version: "1.2.1"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.dartlang.org"
source: hosted
- version: "1.1.0"
+ version: "1.1.1"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.dartlang.org"
source: hosted
- version: "1.15.0"
+ version: "1.16.0"
fake_async:
dependency: transitive
description:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
- version: "1.2.0"
+ version: "1.3.1"
flutter:
dependency: "direct main"
description: flutter
@@ -66,21 +59,28 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
- version: "0.12.10"
+ version: "0.12.12"
+ material_color_utilities:
+ dependency: transitive
+ description:
+ name: material_color_utilities
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "0.1.5"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
- version: "1.7.0"
+ version: "1.8.0"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
- version: "1.8.0"
+ version: "1.8.2"
plugin_platform_interface:
dependency: "direct main"
description:
@@ -99,7 +99,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
- version: "1.8.1"
+ version: "1.9.0"
stack_trace:
dependency: transitive
description:
@@ -120,35 +120,28 @@ packages:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
- version: "1.1.0"
+ version: "1.1.1"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
- version: "1.2.0"
+ version: "1.2.1"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
- version: "0.4.2"
- typed_data:
- dependency: transitive
- description:
- name: typed_data
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.3.0"
+ version: "0.4.12"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
- version: "2.1.0"
+ version: "2.1.2"
sdks:
- dart: ">=2.12.0 <3.0.0"
+ dart: ">=2.17.0-0 <3.0.0"
flutter: ">=1.20.0"
diff --git a/libphonenumber_plugin/.idea/libphonenumber_plugin.iml b/libphonenumber_plugin/.idea/libphonenumber_plugin.iml
index 5ef99d4..c1b769b 100644
--- a/libphonenumber_plugin/.idea/libphonenumber_plugin.iml
+++ b/libphonenumber_plugin/.idea/libphonenumber_plugin.iml
@@ -10,6 +10,15 @@
+
+
+
+
+
+
+
+
+
diff --git a/libphonenumber_plugin/.idea/libraries/Dart_Packages.xml b/libphonenumber_plugin/.idea/libraries/Dart_Packages.xml
index a90d3ee..0307faf 100644
--- a/libphonenumber_plugin/.idea/libraries/Dart_Packages.xml
+++ b/libphonenumber_plugin/.idea/libraries/Dart_Packages.xml
@@ -5,230 +5,214 @@
-
+
-
+
-
-
-
-
-
-
-
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
-
-
-
-
-
-
-
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/libphonenumber_plugin/.idea/libraries/Dart_SDK.xml b/libphonenumber_plugin/.idea/libraries/Dart_SDK.xml
index e450131..41e82d7 100644
--- a/libphonenumber_plugin/.idea/libraries/Dart_SDK.xml
+++ b/libphonenumber_plugin/.idea/libraries/Dart_SDK.xml
@@ -1,26 +1,25 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/libphonenumber_plugin/.idea/libraries/Flutter_Plugins.xml b/libphonenumber_plugin/.idea/libraries/Flutter_Plugins.xml
index 6fcf1c9..29954a1 100644
--- a/libphonenumber_plugin/.idea/libraries/Flutter_Plugins.xml
+++ b/libphonenumber_plugin/.idea/libraries/Flutter_Plugins.xml
@@ -2,8 +2,7 @@
-
-
+
diff --git a/libphonenumber_plugin/.idea/workspace.xml b/libphonenumber_plugin/.idea/workspace.xml
index fe9f8dc..6f71a5d 100644
--- a/libphonenumber_plugin/.idea/workspace.xml
+++ b/libphonenumber_plugin/.idea/workspace.xml
@@ -22,21 +22,24 @@
-
+
+
-
-
+
+
+
+
@@ -47,7 +50,9 @@
+
+
@@ -75,6 +80,28 @@
1609684921703
+
+ 1673246343927
+
+
+
+ 1673246343928
+
+
+ 1673247826477
+
+
+
+ 1673247826477
+
+
+ 1673261438343
+
+
+
+ 1673261438343
+
+
@@ -87,6 +114,10 @@
-
+
+
+
+
+
\ No newline at end of file
diff --git a/libphonenumber_plugin/android/build.gradle b/libphonenumber_plugin/android/build.gradle
index 440f017..da89519 100644
--- a/libphonenumber_plugin/android/build.gradle
+++ b/libphonenumber_plugin/android/build.gradle
@@ -4,30 +4,32 @@ version '1.0'
buildscript {
repositories {
google()
- jcenter()
+ mavenCentral()
}
dependencies {
- classpath 'com.android.tools.build:gradle:4.1.0'
+ classpath 'com.android.tools.build:gradle:4.1.3'
}
}
rootProject.allprojects {
repositories {
google()
- jcenter()
+ mavenCentral()
}
}
apply plugin: 'com.android.library'
android {
- compileSdkVersion 30
+ compileSdkVersion 33
defaultConfig {
minSdkVersion 16
}
+
dependencies {
- compileOnly rootProject.findProject(":libphonenumber")
+ api 'com.googlecode.libphonenumber:libphonenumber:8.13.4'
+ api 'com.googlecode.libphonenumber:carrier:1.188'
}
}
diff --git a/libphonenumber_plugin/android/src/main/java/com/example/libphonenumber_plugin/LibphonenumberPlugin.java b/libphonenumber_plugin/android/src/main/java/com/example/libphonenumber_plugin/LibphonenumberPlugin.java
index 1a7b3e4..4666161 100644
--- a/libphonenumber_plugin/android/src/main/java/com/example/libphonenumber_plugin/LibphonenumberPlugin.java
+++ b/libphonenumber_plugin/android/src/main/java/com/example/libphonenumber_plugin/LibphonenumberPlugin.java
@@ -2,7 +2,14 @@
import androidx.annotation.NonNull;
+import com.google.i18n.phonenumbers.AsYouTypeFormatter;
+import com.google.i18n.phonenumbers.NumberParseException;
+import com.google.i18n.phonenumbers.PhoneNumberToCarrierMapper;
+import com.google.i18n.phonenumbers.PhoneNumberUtil;
+import com.google.i18n.phonenumbers.Phonenumber;
+
import java.util.HashMap;
+import java.util.Locale;
import java.util.Map;
import io.flutter.embedding.engine.plugins.FlutterPlugin;
@@ -21,14 +28,14 @@ public class LibphonenumberPlugin implements FlutterPlugin, MethodCallHandler {
/// when the Flutter Engine is detached from the Activity
private MethodChannel channel;
- private com.codeheadlabs.libphonenumber.LibphonenumberPlugin libphonenumberPlugin;
+ private static final PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
+ private static final PhoneNumberToCarrierMapper phoneNumberToCarrierMapper = PhoneNumberToCarrierMapper.getInstance();
+
@Override
public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {
channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "plugin.libphonenumber");
channel.setMethodCallHandler(this);
-
- libphonenumberPlugin = new com.codeheadlabs.libphonenumber.LibphonenumberPlugin();
}
@Override
@@ -40,12 +47,22 @@ public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
switch (call.method) {
case "isValidPhoneNumber":
+ handleIsValidPhoneNumber(call, result);
+ break;
case "getNameForNumber":
+ handleGetNameForNumber(call, result);
+ break;
case "normalizePhoneNumber":
+ handleNormalizePhoneNumber(call, result);
+ break;
case "getRegionInfo":
+ handleGetRegionInfo(call, result);
+ break;
case "getNumberType":
+ handleGetNumberType(call, result);
+ break;
case "formatAsYouType":
- onDirectMethodCall(call, result);
+ handleFormatAsYouType(call, result);
break;
default:
result.notImplemented();
@@ -53,17 +70,123 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
}
}
- private void onDirectMethodCall(MethodCall call, Result result) {
+ private void handleIsValidPhoneNumber(MethodCall call, Result result) {
+ String phoneNumber = call.argument("phoneNumber");
+ String isoCode = call.argument("isoCode");
+
+ try {
+ Phonenumber.PhoneNumber p = phoneUtil.parse(phoneNumber, isoCode);
+ result.success(phoneUtil.isValidNumber(p));
+ } catch (NumberParseException e) {
+ result.error("NumberParseException", e.getMessage(), null);
+ }
+ }
+
+ private void handleGetNameForNumber(MethodCall call, Result result) {
+ String phoneNumber = call.argument("phoneNumber");
+ String isoCode = call.argument("isoCode");
+
+ try {
+ Phonenumber.PhoneNumber p = phoneUtil.parse(phoneNumber, isoCode);
+ result.success(phoneNumberToCarrierMapper.getNameForNumber(p, Locale.getDefault()));
+ } catch (NumberParseException e) {
+ result.error("NumberParseException", e.getMessage(), null);
+ }
+ }
+
+ private void handleNormalizePhoneNumber(MethodCall call, Result result) {
+ String phoneNumber = call.argument("phoneNumber");
+ String isoCode = call.argument("isoCode");
+
+ try {
+ Phonenumber.PhoneNumber p = phoneUtil.parse(phoneNumber, isoCode);
+ final String normalized = phoneUtil.format(p, PhoneNumberUtil.PhoneNumberFormat.E164);
+ result.success(normalized);
+ } catch (NumberParseException e) {
+ result.error("NumberParseException", e.getMessage(), null);
+ }
+ }
+
+ private void handleGetRegionInfo(MethodCall call, Result result) {
String phoneNumber = call.argument("phoneNumber");
String isoCode = call.argument("isoCode");
- Map