From e7eb955226190586d23725f79818ce002280856e Mon Sep 17 00:00:00 2001 From: Max Lapides Date: Sat, 18 May 2024 19:48:07 -0700 Subject: [PATCH 1/3] upgrade: migrate from package:js to dart:js_interop --- .../lib/src/utils/enums/country_code_source.dart | 1 + .../lib/src/utils/enums/phone_number_format.dart | 1 + .../lib/src/utils/enums/phone_number_type.dart | 1 + .../lib/src/utils/enums/short_number_cost.dart | 1 + ...number_platform_interface_method_channel_test.dart | 11 +++++++---- .../lib/src/interop/asyoutypeformatter_interop.dart | 2 +- .../lib/src/interop/libphonenumber_interop.dart | 5 +++-- .../lib/src/interop/phonemetadata_interop.dart | 2 +- .../lib/src/interop/phonenumber_interop.dart | 2 +- .../lib/src/interop/phonenumberutil_interop.dart | 2 +- .../lib/src/interop/shortnumberinfo_interop.dart | 2 +- .../lib/src/interop/utils/stringbuffer.dart | 2 +- libphonenumber_web/pubspec.yaml | 2 -- 13 files changed, 20 insertions(+), 14 deletions(-) diff --git a/libphonenumber_platform_interface/lib/src/utils/enums/country_code_source.dart b/libphonenumber_platform_interface/lib/src/utils/enums/country_code_source.dart index 6011bae..8b172f3 100644 --- a/libphonenumber_platform_interface/lib/src/utils/enums/country_code_source.dart +++ b/libphonenumber_platform_interface/lib/src/utils/enums/country_code_source.dart @@ -11,6 +11,7 @@ /// FROM_NUMBER_WITHOUT_PLUS_SIGN: 10, /// FROM_DEFAULT_COUNTRY: 20 /// }; +library; enum CountryCodeSource { UNSPECIFIED(value: 0), diff --git a/libphonenumber_platform_interface/lib/src/utils/enums/phone_number_format.dart b/libphonenumber_platform_interface/lib/src/utils/enums/phone_number_format.dart index c4f909c..2976a74 100644 --- a/libphonenumber_platform_interface/lib/src/utils/enums/phone_number_format.dart +++ b/libphonenumber_platform_interface/lib/src/utils/enums/phone_number_format.dart @@ -22,6 +22,7 @@ /// NATIONAL: 2, /// RFC3966: 3 /// }; +library; enum PhoneNumberFormat { E164(value: 0), //: 0, diff --git a/libphonenumber_platform_interface/lib/src/utils/enums/phone_number_type.dart b/libphonenumber_platform_interface/lib/src/utils/enums/phone_number_type.dart index d944220..51827d7 100644 --- a/libphonenumber_platform_interface/lib/src/utils/enums/phone_number_type.dart +++ b/libphonenumber_platform_interface/lib/src/utils/enums/phone_number_type.dart @@ -35,6 +35,7 @@ /// // patterns for a specific region. /// UNKNOWN: -1 /// }; +library; enum PhoneNumberType { FIXED_LINE(value: 0), // : 0, diff --git a/libphonenumber_platform_interface/lib/src/utils/enums/short_number_cost.dart b/libphonenumber_platform_interface/lib/src/utils/enums/short_number_cost.dart index fb2886c..b006bef 100644 --- a/libphonenumber_platform_interface/lib/src/utils/enums/short_number_cost.dart +++ b/libphonenumber_platform_interface/lib/src/utils/enums/short_number_cost.dart @@ -9,6 +9,7 @@ /// PREMIUM_RATE: 2, /// UNKNOWN_COST: 3 /// }; +library; enum ShortNumberCost { TOLL_FREE(value: 0), diff --git a/libphonenumber_platform_interface/test/libphonenumber_platform_interface_method_channel_test.dart b/libphonenumber_platform_interface/test/libphonenumber_platform_interface_method_channel_test.dart index 7005486..b6bde8d 100644 --- a/libphonenumber_platform_interface/test/libphonenumber_platform_interface_method_channel_test.dart +++ b/libphonenumber_platform_interface/test/libphonenumber_platform_interface_method_channel_test.dart @@ -10,7 +10,8 @@ void main() { TestWidgetsFlutterBinding.ensureInitialized(); setUp(() { - channel.setMockMethodCallHandler((MethodCall methodCall) async { + TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger + .setMockMethodCallHandler(channel, (methodCall) async { switch (methodCall.method) { case 'formatAsYouType': return '+234 808 012 3456'; @@ -31,11 +32,13 @@ void main() { case 'getFormattedExampleNumber': return '+234 808 012 3456'; } + return null; }); }); tearDown(() { - channel.setMockMethodCallHandler(null); + TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger + .setMockMethodCallHandler(channel, null); }); test('TEST formatAsYouType', () async { @@ -65,8 +68,8 @@ void main() { }); test('TEST normalizePhoneNumber', () async { - final normalizedNumber = - await platform.normalizePhoneNumber('+2348080123456', 'NG', PhoneNumberFormat.E164); + final normalizedNumber = await platform.normalizePhoneNumber( + '+2348080123456', 'NG', PhoneNumberFormat.E164); expect(normalizedNumber, '+2348080123456'); }); diff --git a/libphonenumber_web/lib/src/interop/asyoutypeformatter_interop.dart b/libphonenumber_web/lib/src/interop/asyoutypeformatter_interop.dart index 9b50853..4579778 100644 --- a/libphonenumber_web/lib/src/interop/asyoutypeformatter_interop.dart +++ b/libphonenumber_web/lib/src/interop/asyoutypeformatter_interop.dart @@ -1,4 +1,4 @@ -part of libphonenumber_interop; +part of 'libphonenumber_interop.dart'; @JS('AsYouTypeFormatter') class AsYouTypeFormatterJsImpl { diff --git a/libphonenumber_web/lib/src/interop/libphonenumber_interop.dart b/libphonenumber_web/lib/src/interop/libphonenumber_interop.dart index ae43613..dfd06a6 100644 --- a/libphonenumber_web/lib/src/interop/libphonenumber_interop.dart +++ b/libphonenumber_web/lib/src/interop/libphonenumber_interop.dart @@ -1,11 +1,12 @@ @JS('libphonenumber') library libphonenumber_interop; -import 'package:js/js.dart'; +import 'dart:js_interop'; + import 'package:libphonenumber_web/src/interop/utils/stringbuffer.dart'; part 'asyoutypeformatter_interop.dart'; +part 'phonemetadata_interop.dart'; part 'phonenumber_interop.dart'; part 'phonenumberutil_interop.dart'; -part 'phonemetadata_interop.dart'; part 'shortnumberinfo_interop.dart'; diff --git a/libphonenumber_web/lib/src/interop/phonemetadata_interop.dart b/libphonenumber_web/lib/src/interop/phonemetadata_interop.dart index b84405f..7115e45 100644 --- a/libphonenumber_web/lib/src/interop/phonemetadata_interop.dart +++ b/libphonenumber_web/lib/src/interop/phonemetadata_interop.dart @@ -1,4 +1,4 @@ -part of libphonenumber_interop; +part of 'libphonenumber_interop.dart'; @JS('NumberFormat') class NumberFormatJsImpl { diff --git a/libphonenumber_web/lib/src/interop/phonenumber_interop.dart b/libphonenumber_web/lib/src/interop/phonenumber_interop.dart index 79674b9..ec5d122 100644 --- a/libphonenumber_web/lib/src/interop/phonenumber_interop.dart +++ b/libphonenumber_web/lib/src/interop/phonenumber_interop.dart @@ -1,4 +1,4 @@ -part of libphonenumber_interop; +part of 'libphonenumber_interop.dart'; @JS('PhoneNumber') class PhoneNumberJsImpl { diff --git a/libphonenumber_web/lib/src/interop/phonenumberutil_interop.dart b/libphonenumber_web/lib/src/interop/phonenumberutil_interop.dart index e5b1d5c..cb1e58c 100644 --- a/libphonenumber_web/lib/src/interop/phonenumberutil_interop.dart +++ b/libphonenumber_web/lib/src/interop/phonenumberutil_interop.dart @@ -1,4 +1,4 @@ -part of libphonenumber_interop; +part of 'libphonenumber_interop.dart'; @JS('PhoneNumberUtil') class PhoneNumberUtilJsImpl { diff --git a/libphonenumber_web/lib/src/interop/shortnumberinfo_interop.dart b/libphonenumber_web/lib/src/interop/shortnumberinfo_interop.dart index b7f4e89..a1ffb5e 100644 --- a/libphonenumber_web/lib/src/interop/shortnumberinfo_interop.dart +++ b/libphonenumber_web/lib/src/interop/shortnumberinfo_interop.dart @@ -1,4 +1,4 @@ -part of libphonenumber_interop; +part of 'libphonenumber_interop.dart'; @JS('ShortNumberInfo') class ShortNumberInfoJsImpl { diff --git a/libphonenumber_web/lib/src/interop/utils/stringbuffer.dart b/libphonenumber_web/lib/src/interop/utils/stringbuffer.dart index 094efc1..f94e864 100644 --- a/libphonenumber_web/lib/src/interop/utils/stringbuffer.dart +++ b/libphonenumber_web/lib/src/interop/utils/stringbuffer.dart @@ -3,7 +3,7 @@ @JS() library stringbuffer; -import 'package:js/js.dart'; +import 'dart:js_interop'; @JS('StringBuffer') class StringBufferJsImpl { diff --git a/libphonenumber_web/pubspec.yaml b/libphonenumber_web/pubspec.yaml index f6f4bb1..90f967e 100644 --- a/libphonenumber_web/pubspec.yaml +++ b/libphonenumber_web/pubspec.yaml @@ -12,8 +12,6 @@ dependencies: sdk: flutter flutter_web_plugins: sdk: flutter - - js: ^0.6.7 libphonenumber_platform_interface: ^0.4.2 dev_dependencies: From 255926d0df7e5ba497fa7758a02ea01107dbcd8f Mon Sep 17 00:00:00 2001 From: Max Lapides Date: Sat, 18 May 2024 19:56:07 -0700 Subject: [PATCH 2/3] add staticInterops --- .../lib/src/interop/asyoutypeformatter_interop.dart | 1 + libphonenumber_web/lib/src/interop/phonemetadata_interop.dart | 4 ++++ libphonenumber_web/lib/src/interop/phonenumber_interop.dart | 1 + .../lib/src/interop/phonenumberutil_interop.dart | 1 + .../lib/src/interop/shortnumberinfo_interop.dart | 1 + libphonenumber_web/lib/src/interop/utils/stringbuffer.dart | 1 + 6 files changed, 9 insertions(+) diff --git a/libphonenumber_web/lib/src/interop/asyoutypeformatter_interop.dart b/libphonenumber_web/lib/src/interop/asyoutypeformatter_interop.dart index 4579778..85f8ebd 100644 --- a/libphonenumber_web/lib/src/interop/asyoutypeformatter_interop.dart +++ b/libphonenumber_web/lib/src/interop/asyoutypeformatter_interop.dart @@ -1,6 +1,7 @@ part of 'libphonenumber_interop.dart'; @JS('AsYouTypeFormatter') +@staticInterop class AsYouTypeFormatterJsImpl { external AsYouTypeFormatterJsImpl(String regionCode); diff --git a/libphonenumber_web/lib/src/interop/phonemetadata_interop.dart b/libphonenumber_web/lib/src/interop/phonemetadata_interop.dart index 7115e45..57e88ec 100644 --- a/libphonenumber_web/lib/src/interop/phonemetadata_interop.dart +++ b/libphonenumber_web/lib/src/interop/phonemetadata_interop.dart @@ -1,6 +1,7 @@ part of 'libphonenumber_interop.dart'; @JS('NumberFormat') +@staticInterop class NumberFormatJsImpl { @JS('getPattern') external String getPattern(); @@ -112,6 +113,7 @@ class NumberFormatJsImpl { } @JS('PhoneNumberDesc') +@staticInterop class PhoneNumberDescJsImpl { @JS('getNationalNumberPattern') external String getNationalNumberPattern(); @@ -193,6 +195,7 @@ class PhoneNumberDescJsImpl { } @JS('PhoneMetadata') +@staticInterop class PhoneMetadataJsImpl { @JS('getGeneralDesc') external PhoneNumberDescJsImpl getGeneralDesc(); @@ -760,6 +763,7 @@ class PhoneMetadataJsImpl { } @JS('PhoneMetadataCollection') +@staticInterop class PhoneMetadataCollectionJsImpl { @JS('getMetadata') external PhoneMetadataJsImpl getMetadata(int index); diff --git a/libphonenumber_web/lib/src/interop/phonenumber_interop.dart b/libphonenumber_web/lib/src/interop/phonenumber_interop.dart index ec5d122..ae3f0cf 100644 --- a/libphonenumber_web/lib/src/interop/phonenumber_interop.dart +++ b/libphonenumber_web/lib/src/interop/phonenumber_interop.dart @@ -1,6 +1,7 @@ part of 'libphonenumber_interop.dart'; @JS('PhoneNumber') +@staticInterop class PhoneNumberJsImpl { @JS('getCountryCode') external int getCountryCode(); diff --git a/libphonenumber_web/lib/src/interop/phonenumberutil_interop.dart b/libphonenumber_web/lib/src/interop/phonenumberutil_interop.dart index cb1e58c..a7008bd 100644 --- a/libphonenumber_web/lib/src/interop/phonenumberutil_interop.dart +++ b/libphonenumber_web/lib/src/interop/phonenumberutil_interop.dart @@ -1,6 +1,7 @@ part of 'libphonenumber_interop.dart'; @JS('PhoneNumberUtil') +@staticInterop class PhoneNumberUtilJsImpl { external PhoneNumberUtilJsImpl._(); diff --git a/libphonenumber_web/lib/src/interop/shortnumberinfo_interop.dart b/libphonenumber_web/lib/src/interop/shortnumberinfo_interop.dart index a1ffb5e..ebbc35c 100644 --- a/libphonenumber_web/lib/src/interop/shortnumberinfo_interop.dart +++ b/libphonenumber_web/lib/src/interop/shortnumberinfo_interop.dart @@ -1,6 +1,7 @@ part of 'libphonenumber_interop.dart'; @JS('ShortNumberInfo') +@staticInterop class ShortNumberInfoJsImpl { @JS('getInstance') external static ShortNumberInfoJsImpl getInstance(); diff --git a/libphonenumber_web/lib/src/interop/utils/stringbuffer.dart b/libphonenumber_web/lib/src/interop/utils/stringbuffer.dart index f94e864..1299c3e 100644 --- a/libphonenumber_web/lib/src/interop/utils/stringbuffer.dart +++ b/libphonenumber_web/lib/src/interop/utils/stringbuffer.dart @@ -6,6 +6,7 @@ library stringbuffer; import 'dart:js_interop'; @JS('StringBuffer') +@staticInterop class StringBufferJsImpl { external StringBufferJsImpl(dynamic optA1, [dynamic varArgs = '']); From f689dec32854a59169559258fda98bdc26de34d8 Mon Sep 17 00:00:00 2001 From: Max Lapides Date: Sat, 18 May 2024 21:33:48 -0700 Subject: [PATCH 3/3] Revert "add staticInterops" This reverts commit 255926d0df7e5ba497fa7758a02ea01107dbcd8f. --- .../lib/src/interop/asyoutypeformatter_interop.dart | 1 - libphonenumber_web/lib/src/interop/phonemetadata_interop.dart | 4 ---- libphonenumber_web/lib/src/interop/phonenumber_interop.dart | 1 - .../lib/src/interop/phonenumberutil_interop.dart | 1 - .../lib/src/interop/shortnumberinfo_interop.dart | 1 - libphonenumber_web/lib/src/interop/utils/stringbuffer.dart | 1 - 6 files changed, 9 deletions(-) diff --git a/libphonenumber_web/lib/src/interop/asyoutypeformatter_interop.dart b/libphonenumber_web/lib/src/interop/asyoutypeformatter_interop.dart index 85f8ebd..4579778 100644 --- a/libphonenumber_web/lib/src/interop/asyoutypeformatter_interop.dart +++ b/libphonenumber_web/lib/src/interop/asyoutypeformatter_interop.dart @@ -1,7 +1,6 @@ part of 'libphonenumber_interop.dart'; @JS('AsYouTypeFormatter') -@staticInterop class AsYouTypeFormatterJsImpl { external AsYouTypeFormatterJsImpl(String regionCode); diff --git a/libphonenumber_web/lib/src/interop/phonemetadata_interop.dart b/libphonenumber_web/lib/src/interop/phonemetadata_interop.dart index 57e88ec..7115e45 100644 --- a/libphonenumber_web/lib/src/interop/phonemetadata_interop.dart +++ b/libphonenumber_web/lib/src/interop/phonemetadata_interop.dart @@ -1,7 +1,6 @@ part of 'libphonenumber_interop.dart'; @JS('NumberFormat') -@staticInterop class NumberFormatJsImpl { @JS('getPattern') external String getPattern(); @@ -113,7 +112,6 @@ class NumberFormatJsImpl { } @JS('PhoneNumberDesc') -@staticInterop class PhoneNumberDescJsImpl { @JS('getNationalNumberPattern') external String getNationalNumberPattern(); @@ -195,7 +193,6 @@ class PhoneNumberDescJsImpl { } @JS('PhoneMetadata') -@staticInterop class PhoneMetadataJsImpl { @JS('getGeneralDesc') external PhoneNumberDescJsImpl getGeneralDesc(); @@ -763,7 +760,6 @@ class PhoneMetadataJsImpl { } @JS('PhoneMetadataCollection') -@staticInterop class PhoneMetadataCollectionJsImpl { @JS('getMetadata') external PhoneMetadataJsImpl getMetadata(int index); diff --git a/libphonenumber_web/lib/src/interop/phonenumber_interop.dart b/libphonenumber_web/lib/src/interop/phonenumber_interop.dart index ae3f0cf..ec5d122 100644 --- a/libphonenumber_web/lib/src/interop/phonenumber_interop.dart +++ b/libphonenumber_web/lib/src/interop/phonenumber_interop.dart @@ -1,7 +1,6 @@ part of 'libphonenumber_interop.dart'; @JS('PhoneNumber') -@staticInterop class PhoneNumberJsImpl { @JS('getCountryCode') external int getCountryCode(); diff --git a/libphonenumber_web/lib/src/interop/phonenumberutil_interop.dart b/libphonenumber_web/lib/src/interop/phonenumberutil_interop.dart index a7008bd..cb1e58c 100644 --- a/libphonenumber_web/lib/src/interop/phonenumberutil_interop.dart +++ b/libphonenumber_web/lib/src/interop/phonenumberutil_interop.dart @@ -1,7 +1,6 @@ part of 'libphonenumber_interop.dart'; @JS('PhoneNumberUtil') -@staticInterop class PhoneNumberUtilJsImpl { external PhoneNumberUtilJsImpl._(); diff --git a/libphonenumber_web/lib/src/interop/shortnumberinfo_interop.dart b/libphonenumber_web/lib/src/interop/shortnumberinfo_interop.dart index ebbc35c..a1ffb5e 100644 --- a/libphonenumber_web/lib/src/interop/shortnumberinfo_interop.dart +++ b/libphonenumber_web/lib/src/interop/shortnumberinfo_interop.dart @@ -1,7 +1,6 @@ part of 'libphonenumber_interop.dart'; @JS('ShortNumberInfo') -@staticInterop class ShortNumberInfoJsImpl { @JS('getInstance') external static ShortNumberInfoJsImpl getInstance(); diff --git a/libphonenumber_web/lib/src/interop/utils/stringbuffer.dart b/libphonenumber_web/lib/src/interop/utils/stringbuffer.dart index 1299c3e..f94e864 100644 --- a/libphonenumber_web/lib/src/interop/utils/stringbuffer.dart +++ b/libphonenumber_web/lib/src/interop/utils/stringbuffer.dart @@ -6,7 +6,6 @@ library stringbuffer; import 'dart:js_interop'; @JS('StringBuffer') -@staticInterop class StringBufferJsImpl { external StringBufferJsImpl(dynamic optA1, [dynamic varArgs = '']);