From 837776cbe0d5f9b89f7b2e44832e6d37274361f2 Mon Sep 17 00:00:00 2001 From: Abdalqader27 Date: Tue, 28 Nov 2023 18:01:25 +0400 Subject: [PATCH 1/8] feat: added favourite countries to the top of list --- example/android/app/build.gradle | 2 +- example/android/build.gradle | 2 +- example/android/gradle.properties | 7 +- example/lib/main.dart | 1 + example/pubspec.lock | 28 ++++---- lib/country_picker_dialog.dart | 108 ++++++++++++++++++++---------- lib/helpers.dart | 5 ++ lib/intl_phone_field.dart | 10 ++- pubspec.lock | 34 +++++----- 9 files changed, 128 insertions(+), 69 deletions(-) diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 7ab1667a..3bafe1b1 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -39,7 +39,7 @@ android { defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.example.intl_phone_field_example" - minSdkVersion 16 + minSdkVersion flutter.minSdkVersion targetSdkVersion 32 versionCode flutterVersionCode.toInteger() versionName flutterVersionName diff --git a/example/android/build.gradle b/example/android/build.gradle index 8c40237d..f87c9520 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -26,6 +26,6 @@ subprojects { project.evaluationDependsOn(':app') } -task clean(type: Delete) { +tasks.register("clean", Delete) { delete rootProject.buildDir } diff --git a/example/android/gradle.properties b/example/android/gradle.properties index 38c8d454..ca130d67 100644 --- a/example/android/gradle.properties +++ b/example/android/gradle.properties @@ -1,4 +1,9 @@ -org.gradle.jvmargs=-Xmx1536M +org.gradle.jvmargs=-Xmx1536M \ +--add-exports=java.base/sun.nio.ch=ALL-UNNAMED \ +--add-opens=java.base/java.lang=ALL-UNNAMED \ +--add-opens=java.base/java.lang.reflect=ALL-UNNAMED \ +--add-opens=java.base/java.io=ALL-UNNAMED \ +--add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED android.enableR8=true android.useAndroidX=true android.enableJetifier=true diff --git a/example/lib/main.dart b/example/lib/main.dart index 4140452f..5167c511 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -54,6 +54,7 @@ class _MyAppState extends State { height: 10, ), IntlPhoneField( + favourite: ['AE'], focusNode: focusNode, decoration: InputDecoration( labelText: 'Phone Number', diff --git a/example/pubspec.lock b/example/pubspec.lock index aa66e30c..292cfa41 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -37,10 +37,10 @@ packages: dependency: transitive description: name: collection - sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687 + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a url: "https://pub.dev" source: hosted - version: "1.17.2" + version: "1.18.0" fake_async: dependency: transitive description: @@ -65,7 +65,7 @@ packages: path: ".." relative: true source: path - version: "3.2.0" + version: "3.3.0" matcher: dependency: transitive description: @@ -86,10 +86,10 @@ packages: dependency: transitive description: name: meta - sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" + sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e url: "https://pub.dev" source: hosted - version: "1.9.1" + version: "1.10.0" path: dependency: transitive description: @@ -115,18 +115,18 @@ packages: dependency: transitive description: name: stack_trace - sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5 + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" url: "https://pub.dev" source: hosted - version: "1.11.0" + version: "1.11.1" stream_channel: dependency: transitive description: name: stream_channel - sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8" + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 url: "https://pub.dev" source: hosted - version: "2.1.1" + version: "2.1.2" string_scanner: dependency: transitive description: @@ -147,10 +147,10 @@ packages: dependency: transitive description: name: test_api - sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8" + sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" url: "https://pub.dev" source: hosted - version: "0.6.0" + version: "0.6.1" vector_math: dependency: transitive description: @@ -163,9 +163,9 @@ packages: dependency: transitive description: name: web - sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10 + sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152 url: "https://pub.dev" source: hosted - version: "0.1.4-beta" + version: "0.3.0" sdks: - dart: ">=3.1.0-185.0.dev <4.0.0" + dart: ">=3.2.0-194.0.dev <4.0.0" diff --git a/lib/country_picker_dialog.dart b/lib/country_picker_dialog.dart index 8d078a60..503fd1a9 100644 --- a/lib/country_picker_dialog.dart +++ b/lib/country_picker_dialog.dart @@ -44,11 +44,13 @@ class CountryPickerDialog extends StatefulWidget { final ValueChanged onCountryChanged; final String searchText; final List filteredCountries; + final List favorite; final PickerDialogStyle? style; final String languageCode; const CountryPickerDialog({ Key? key, + this.favorite = const [], required this.searchText, required this.languageCode, required this.countryList, @@ -65,10 +67,16 @@ class CountryPickerDialog extends StatefulWidget { class _CountryPickerDialogState extends State { late List _filteredCountries; late Country _selectedCountry; + late List _filteredFavoriteCountries; + late List _favoriteCountries; @override void initState() { _selectedCountry = widget.selectedCountry; + _favoriteCountries = getCountriesByCountriesCode(widget.favorite, widget.filteredCountries); + + _filteredFavoriteCountries = _favoriteCountries; + _filteredCountries = widget.filteredCountries.toList() ..sort( (a, b) => a.localizedName(widget.languageCode).compareTo(b.localizedName(widget.languageCode)), @@ -104,50 +112,37 @@ class _CountryPickerDialogState extends State { labelText: widget.searchText, ), onChanged: (value) { - _filteredCountries = widget.countryList.stringSearch(value) - ..sort( - (a, b) => a.localizedName(widget.languageCode).compareTo(b.localizedName(widget.languageCode)), - ); + search(value); if (mounted) setState(() {}); }, ), ), const SizedBox(height: 20), Expanded( - child: ListView.builder( + child: CustomScrollView( shrinkWrap: true, - itemCount: _filteredCountries.length, - itemBuilder: (ctx, index) => Column( - children: [ - ListTile( - leading: kIsWeb - ? Image.asset( - 'assets/flags/${_filteredCountries[index].code.toLowerCase()}.png', - package: 'intl_phone_field', - width: 32, - ) - : Text( - _filteredCountries[index].flag, - style: const TextStyle(fontSize: 18), - ), - contentPadding: widget.style?.listTilePadding, - title: Text( - _filteredCountries[index].localizedName(widget.languageCode), - style: widget.style?.countryNameStyle ?? const TextStyle(fontWeight: FontWeight.w700), - ), - trailing: Text( - '+${_filteredCountries[index].dialCode}', - style: widget.style?.countryCodeStyle ?? const TextStyle(fontWeight: FontWeight.w700), + slivers: [ + if (_filteredFavoriteCountries.isNotEmpty) ...[ + SliverList( + delegate: SliverChildBuilderDelegate( + (BuildContext context, int index) { + final Country item = _filteredFavoriteCountries[index]; + return _buildCountryPickerItem(item); + }, + childCount: _filteredFavoriteCountries.length, ), - onTap: () { - _selectedCountry = _filteredCountries[index]; - widget.onCountryChanged(_selectedCountry); - Navigator.of(context).pop(); - }, ), - widget.style?.listTileDivider ?? const Divider(thickness: 1), ], - ), + SliverList( + delegate: SliverChildBuilderDelegate( + (BuildContext context, int index) { + final Country item = _filteredCountries[index]; + return _buildCountryPickerItem(item); + }, + childCount: _filteredCountries.length, + ), + ) + ], ), ), ], @@ -155,4 +150,49 @@ class _CountryPickerDialogState extends State { ), ); } + + void search(String value) { + _filteredCountries = widget.countryList + .stringSearch(value) + .where((item) => widget.favorite.any((code) => item.code != code)) + .toList() + ..sort( + (a, b) => a.localizedName(widget.languageCode).compareTo(b.localizedName(widget.languageCode)), + ); + _filteredFavoriteCountries = _favoriteCountries.stringSearch(value); + } + + Widget _buildCountryPickerItem(Country item) { + return Column( + children: [ + ListTile( + leading: kIsWeb + ? Image.asset( + 'assets/flags/${item.code.toLowerCase()}.png', + package: 'intl_phone_field', + width: 32, + ) + : Text( + item.flag, + style: const TextStyle(fontSize: 18), + ), + contentPadding: widget.style?.listTilePadding, + title: Text( + item.localizedName(widget.languageCode), + style: widget.style?.countryNameStyle ?? const TextStyle(fontWeight: FontWeight.w700), + ), + trailing: Text( + '+${item.dialCode}', + style: widget.style?.countryCodeStyle ?? const TextStyle(fontWeight: FontWeight.w700), + ), + onTap: () { + _selectedCountry = item; + widget.onCountryChanged(_selectedCountry); + Navigator.of(context).pop(); + }, + ), + widget.style?.listTileDivider ?? const Divider(thickness: 1), + ], + ); + } } diff --git a/lib/helpers.dart b/lib/helpers.dart index ab3691d4..bc3b581a 100644 --- a/lib/helpers.dart +++ b/lib/helpers.dart @@ -13,6 +13,11 @@ String removeDiacritics(String str) { return str; } +List getCountriesByCountriesCode(List countriesCode, List countries) { + // Filter the countries based on the provided country codes + return countries.where((country) => countriesCode.contains(country.code)).toList(); +} + extension CountryExtensions on List { List stringSearch(String search) { search = removeDiacritics(search.toLowerCase()); diff --git a/lib/intl_phone_field.dart b/lib/intl_phone_field.dart index a28ddafa..b0143ce4 100644 --- a/lib/intl_phone_field.dart +++ b/lib/intl_phone_field.dart @@ -249,6 +249,9 @@ class IntlPhoneField extends StatefulWidget { /// If null, default magnification configuration will be used. final TextMagnifierConfiguration? magnifierConfiguration; + /// added favorite countries to the top of the list + final List favourite; + const IntlPhoneField({ Key? key, this.formFieldKey, @@ -294,6 +297,7 @@ class IntlPhoneField extends StatefulWidget { this.cursorWidth = 2.0, this.showCursor = true, this.pickerDialogStyle, + this.favourite = const [], this.flagsButtonMargin = EdgeInsets.zero, this.magnifierConfiguration, }) : super(key: key); @@ -314,7 +318,9 @@ class _IntlPhoneFieldState extends State { void initState() { super.initState(); _countryList = widget.countries ?? countries; - filteredCountries = _countryList; + + filteredCountries = _countryList.where((item) => widget.favourite.any((code) => item.code != code)).toList(); + number = widget.initialValue ?? ''; if (widget.initialCountryCode == null && number.startsWith('+')) { number = number.substring(1); @@ -357,11 +363,13 @@ class _IntlPhoneFieldState extends State { Future _changeCountry() async { filteredCountries = _countryList; + await showDialog( context: context, useRootNavigator: false, builder: (context) => StatefulBuilder( builder: (ctx, setState) => CountryPickerDialog( + favorite: widget.favourite, languageCode: widget.languageCode.toLowerCase(), style: widget.pickerDialogStyle, filteredCountries: filteredCountries, diff --git a/pubspec.lock b/pubspec.lock index 9fad3df1..39d36ae3 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -61,10 +61,10 @@ packages: dependency: transitive description: name: collection - sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687 + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a url: "https://pub.dev" source: hosted - version: "1.17.2" + version: "1.18.0" convert: dependency: transitive description: @@ -207,10 +207,10 @@ packages: dependency: transitive description: name: meta - sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" + sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e url: "https://pub.dev" source: hosted - version: "1.9.1" + version: "1.10.0" mime: dependency: transitive description: @@ -324,18 +324,18 @@ packages: dependency: transitive description: name: stack_trace - sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5 + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" url: "https://pub.dev" source: hosted - version: "1.11.0" + version: "1.11.1" stream_channel: dependency: transitive description: name: stream_channel - sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8" + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 url: "https://pub.dev" source: hosted - version: "2.1.1" + version: "2.1.2" string_scanner: dependency: transitive description: @@ -356,26 +356,26 @@ packages: dependency: "direct dev" description: name: test - sha256: "13b41f318e2a5751c3169137103b60c584297353d4b1761b66029bae6411fe46" + sha256: a1f7595805820fcc05e5c52e3a231aedd0b72972cb333e8c738a8b1239448b6f url: "https://pub.dev" source: hosted - version: "1.24.3" + version: "1.24.9" test_api: dependency: transitive description: name: test_api - sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8" + sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" url: "https://pub.dev" source: hosted - version: "0.6.0" + version: "0.6.1" test_core: dependency: transitive description: name: test_core - sha256: "99806e9e6d95c7b059b7a0fc08f07fc53fabe54a829497f0d9676299f1e8637e" + sha256: a757b14fc47507060a162cc2530d9a4a2f92f5100a952c7443b5cad5ef5b106a url: "https://pub.dev" source: hosted - version: "0.5.3" + version: "0.5.9" typed_data: dependency: transitive description: @@ -412,10 +412,10 @@ packages: dependency: transitive description: name: web - sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10 + sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152 url: "https://pub.dev" source: hosted - version: "0.1.4-beta" + version: "0.3.0" web_socket_channel: dependency: transitive description: @@ -441,4 +441,4 @@ packages: source: hosted version: "3.1.2" sdks: - dart: ">=3.1.0-185.0.dev <4.0.0" + dart: ">=3.2.0-194.0.dev <4.0.0" From 3515f4396e5b2e426668fb945bc16b6904bdffa6 Mon Sep 17 00:00:00 2001 From: Abdalqader27 Date: Wed, 29 Nov 2023 17:27:48 +0400 Subject: [PATCH 2/8] chore: added key to flags btn --- lib/intl_phone_field.dart | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/intl_phone_field.dart b/lib/intl_phone_field.dart index b0143ce4..46f6c30e 100644 --- a/lib/intl_phone_field.dart +++ b/lib/intl_phone_field.dart @@ -13,6 +13,7 @@ import './phone_number.dart'; class IntlPhoneField extends StatefulWidget { /// The TextFormField key. final GlobalKey? formFieldKey; + final ValueKey? flagButtonKey; /// Whether to hide the text being edited (e.g., for passwords). final bool obscureText; @@ -255,6 +256,7 @@ class IntlPhoneField extends StatefulWidget { const IntlPhoneField({ Key? key, this.formFieldKey, + this.flagButtonKey, this.initialCountryCode, this.languageCode = 'en', this.disableAutoFillHints = false, @@ -457,6 +459,7 @@ class _IntlPhoneFieldState extends State { Container _buildFlagsButton() { return Container( + key: widget.flagButtonKey, margin: widget.flagsButtonMargin, child: DecoratedBox( decoration: widget.dropdownDecoration, From 4655991d7022a0bc521d17a127861fb1ca8e5731 Mon Sep 17 00:00:00 2001 From: Abdalqader27 Date: Wed, 29 Nov 2023 17:30:52 +0400 Subject: [PATCH 3/8] chore: change name to plural --- lib/intl_phone_field.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/intl_phone_field.dart b/lib/intl_phone_field.dart index 46f6c30e..e67590dc 100644 --- a/lib/intl_phone_field.dart +++ b/lib/intl_phone_field.dart @@ -13,7 +13,7 @@ import './phone_number.dart'; class IntlPhoneField extends StatefulWidget { /// The TextFormField key. final GlobalKey? formFieldKey; - final ValueKey? flagButtonKey; + final ValueKey? flagsButtonKey; /// Whether to hide the text being edited (e.g., for passwords). final bool obscureText; @@ -256,7 +256,7 @@ class IntlPhoneField extends StatefulWidget { const IntlPhoneField({ Key? key, this.formFieldKey, - this.flagButtonKey, + this.flagsButtonKey, this.initialCountryCode, this.languageCode = 'en', this.disableAutoFillHints = false, @@ -459,7 +459,7 @@ class _IntlPhoneFieldState extends State { Container _buildFlagsButton() { return Container( - key: widget.flagButtonKey, + key: widget.flagsButtonKey, margin: widget.flagsButtonMargin, child: DecoratedBox( decoration: widget.dropdownDecoration, From e648dfc64316e3f2c8535e41171dd78f6938e871 Mon Sep 17 00:00:00 2001 From: Abdalqader27 Date: Wed, 29 Nov 2023 17:31:58 +0400 Subject: [PATCH 4/8] feat: change the verison of the package --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 70c8bc56..da1223be 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: intl_phone_field description: A customised Flutter TextFormField to input international phone number along with country code. -version: 3.3.0 +version: 3.3.1 homepage: https://github.com/vanshg395/intl_phone_field environment: From af7b08e49c1ad7e175d2ae6ec40a54b32bc3cdea Mon Sep 17 00:00:00 2001 From: Abdalqader27 Date: Mon, 1 Jul 2024 22:58:03 +0400 Subject: [PATCH 5/8] fix: fixed country code for lebanon --- example/lib/main.dart | 5 ++- example/pubspec.lock | 57 ++++++++++++++++++++++++---------- example/pubspec.yaml | 2 +- lib/countries.dart | 2 +- pubspec.lock | 71 +++++++++++++++++++++++++++---------------- pubspec.yaml | 4 +-- 6 files changed, 93 insertions(+), 48 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 5167c511..bf71b70c 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -12,7 +12,7 @@ class MyApp extends StatefulWidget { class _MyAppState extends State { GlobalKey _formKey = GlobalKey(); - + final TextEditingController controller = TextEditingController(); FocusNode focusNode = FocusNode(); @override @@ -55,6 +55,7 @@ class _MyAppState extends State { ), IntlPhoneField( favourite: ['AE'], + controller: controller, focusNode: focusNode, decoration: InputDecoration( labelText: 'Phone Number', @@ -78,6 +79,8 @@ class _MyAppState extends State { color: Theme.of(context).primaryColor, textColor: Colors.white, onPressed: () { + print(controller.text); + _formKey.currentState?.validate(); }, ), diff --git a/example/pubspec.lock b/example/pubspec.lock index 292cfa41..01bb0615 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -65,39 +65,63 @@ packages: path: ".." relative: true source: path - version: "3.3.0" + version: "3.3.2" + leak_tracker: + dependency: transitive + description: + name: leak_tracker + sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a" + url: "https://pub.dev" + source: hosted + version: "10.0.4" + leak_tracker_flutter_testing: + dependency: transitive + description: + name: leak_tracker_flutter_testing + sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8" + url: "https://pub.dev" + source: hosted + version: "3.0.3" + leak_tracker_testing: + dependency: transitive + description: + name: leak_tracker_testing + sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3" + url: "https://pub.dev" + source: hosted + version: "3.0.1" matcher: dependency: transitive description: name: matcher - sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb url: "https://pub.dev" source: hosted - version: "0.12.16" + version: "0.12.16+1" material_color_utilities: dependency: transitive description: name: material_color_utilities - sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" + sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" url: "https://pub.dev" source: hosted - version: "0.5.0" + version: "0.8.0" meta: dependency: transitive description: name: meta - sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e + sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136" url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.12.0" path: dependency: transitive description: name: path - sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" url: "https://pub.dev" source: hosted - version: "1.8.3" + version: "1.9.0" sky_engine: dependency: transitive description: flutter @@ -147,10 +171,10 @@ packages: dependency: transitive description: name: test_api - sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" url: "https://pub.dev" source: hosted - version: "0.6.1" + version: "0.7.0" vector_math: dependency: transitive description: @@ -159,13 +183,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.4" - web: + vm_service: dependency: transitive description: - name: web - sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152 + name: vm_service + sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec" url: "https://pub.dev" source: hosted - version: "0.3.0" + version: "14.2.1" sdks: - dart: ">=3.2.0-194.0.dev <4.0.0" + dart: ">=3.3.0 <4.0.0" + flutter: ">=3.18.0-18.0.pre.54" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 5980d734..529ba62c 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -7,7 +7,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev version: 1.0.0+1 environment: - sdk: ">=2.12.0 <3.0.0" + sdk: ">=2.12.0 <4.0.0" dependencies: flutter: diff --git a/lib/countries.dart b/lib/countries.dart index 73bc8d4e..0af654c9 100644 --- a/lib/countries.dart +++ b/lib/countries.dart @@ -3750,7 +3750,7 @@ const List countries = [ flag: "🇱🇧", code: "LB", dialCode: "961", - minLength: 8, + minLength: 7, maxLength: 8, ), Country( diff --git a/pubspec.lock b/pubspec.lock index 39d36ae3..ae902ef2 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -77,10 +77,10 @@ packages: dependency: transitive description: name: coverage - sha256: "2fb815080e44a09b85e0f2ca8a820b15053982b2e714b59267719e8a9ff17097" + sha256: "3945034e86ea203af7a056d98e98e42a5518fff200d6e8e6647e1886b07e936e" url: "https://pub.dev" source: hosted - version: "1.6.3" + version: "1.8.0" crypto: dependency: transitive description: @@ -171,6 +171,30 @@ packages: url: "https://pub.dev" source: hosted version: "0.6.7" + leak_tracker: + dependency: transitive + description: + name: leak_tracker + sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a" + url: "https://pub.dev" + source: hosted + version: "10.0.4" + leak_tracker_flutter_testing: + dependency: transitive + description: + name: leak_tracker_flutter_testing + sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8" + url: "https://pub.dev" + source: hosted + version: "3.0.3" + leak_tracker_testing: + dependency: transitive + description: + name: leak_tracker_testing + sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3" + url: "https://pub.dev" + source: hosted + version: "3.0.1" lints: dependency: transitive description: @@ -191,26 +215,26 @@ packages: dependency: transitive description: name: matcher - sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb url: "https://pub.dev" source: hosted - version: "0.12.16" + version: "0.12.16+1" material_color_utilities: dependency: transitive description: name: material_color_utilities - sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" + sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" url: "https://pub.dev" source: hosted - version: "0.5.0" + version: "0.8.0" meta: dependency: transitive description: name: meta - sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e + sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136" url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.12.0" mime: dependency: transitive description: @@ -239,10 +263,10 @@ packages: dependency: transitive description: name: path - sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" url: "https://pub.dev" source: hosted - version: "1.8.3" + version: "1.9.0" pool: dependency: transitive description: @@ -356,26 +380,26 @@ packages: dependency: "direct dev" description: name: test - sha256: a1f7595805820fcc05e5c52e3a231aedd0b72972cb333e8c738a8b1239448b6f + sha256: "7ee446762c2c50b3bd4ea96fe13ffac69919352bd3b4b17bac3f3465edc58073" url: "https://pub.dev" source: hosted - version: "1.24.9" + version: "1.25.2" test_api: dependency: transitive description: name: test_api - sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" url: "https://pub.dev" source: hosted - version: "0.6.1" + version: "0.7.0" test_core: dependency: transitive description: name: test_core - sha256: a757b14fc47507060a162cc2530d9a4a2f92f5100a952c7443b5cad5ef5b106a + sha256: "2bc4b4ecddd75309300d8096f781c0e3280ca1ef85beda558d33fcbedc2eead4" url: "https://pub.dev" source: hosted - version: "0.5.9" + version: "0.6.0" typed_data: dependency: transitive description: @@ -396,10 +420,10 @@ packages: dependency: transitive description: name: vm_service - sha256: ada49637c27973c183dad90beb6bd781eea4c9f5f955d35da172de0af7bd3440 + sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec" url: "https://pub.dev" source: hosted - version: "11.8.0" + version: "14.2.1" watcher: dependency: transitive description: @@ -408,14 +432,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.1.0" - web: - dependency: transitive - description: - name: web - sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152 - url: "https://pub.dev" - source: hosted - version: "0.3.0" web_socket_channel: dependency: transitive description: @@ -441,4 +457,5 @@ packages: source: hosted version: "3.1.2" sdks: - dart: ">=3.2.0-194.0.dev <4.0.0" + dart: ">=3.3.0 <4.0.0" + flutter: ">=3.18.0-18.0.pre.54" diff --git a/pubspec.yaml b/pubspec.yaml index da1223be..dce07f28 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,10 +1,10 @@ name: intl_phone_field description: A customised Flutter TextFormField to input international phone number along with country code. -version: 3.3.1 +version: v homepage: https://github.com/vanshg395/intl_phone_field environment: - sdk: ">=2.12.0 <3.0.0" + sdk: ">=2.12.0 <4.0.0" dependencies: flutter: From e92b466db6d04a9033168443fe8b4440a942a7cf Mon Sep 17 00:00:00 2001 From: Abdalqader27 Date: Mon, 1 Jul 2024 23:20:41 +0400 Subject: [PATCH 6/8] fix: pump up the to version: 3.3.2 --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index dce07f28..f3a6c468 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: intl_phone_field description: A customised Flutter TextFormField to input international phone number along with country code. -version: v +version: 3.3.2 homepage: https://github.com/vanshg395/intl_phone_field environment: From b6821c4fdf50c224c4266117608ae33db2bbbc93 Mon Sep 17 00:00:00 2001 From: Abdalqader27 Date: Wed, 3 Jul 2024 10:27:12 +0400 Subject: [PATCH 7/8] fix: fixed duplication of countries on the search --- example/lib/main.dart | 2 +- lib/country_picker_dialog.dart | 25 +++++++++++++++++-------- pubspec.yaml | 2 +- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index bf71b70c..c825be30 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -54,7 +54,7 @@ class _MyAppState extends State { height: 10, ), IntlPhoneField( - favourite: ['AE'], + favourite: ['AE','SA','LB'], controller: controller, focusNode: focusNode, decoration: InputDecoration( diff --git a/lib/country_picker_dialog.dart b/lib/country_picker_dialog.dart index 503fd1a9..90efb3cd 100644 --- a/lib/country_picker_dialog.dart +++ b/lib/country_picker_dialog.dart @@ -73,13 +73,16 @@ class _CountryPickerDialogState extends State { @override void initState() { _selectedCountry = widget.selectedCountry; - _favoriteCountries = getCountriesByCountriesCode(widget.favorite, widget.filteredCountries); + _favoriteCountries = + getCountriesByCountriesCode(widget.favorite, widget.filteredCountries); _filteredFavoriteCountries = _favoriteCountries; _filteredCountries = widget.filteredCountries.toList() ..sort( - (a, b) => a.localizedName(widget.languageCode).compareTo(b.localizedName(widget.languageCode)), + (a, b) => a + .localizedName(widget.languageCode) + .compareTo(b.localizedName(widget.languageCode)), ); super.initState(); @@ -103,7 +106,8 @@ class _CountryPickerDialogState extends State { child: Column( children: [ Padding( - padding: widget.style?.searchFieldPadding ?? const EdgeInsets.all(0), + padding: + widget.style?.searchFieldPadding ?? const EdgeInsets.all(0), child: TextField( cursorColor: widget.style?.searchFieldCursorColor, decoration: widget.style?.searchFieldInputDecoration ?? @@ -126,7 +130,8 @@ class _CountryPickerDialogState extends State { SliverList( delegate: SliverChildBuilderDelegate( (BuildContext context, int index) { - final Country item = _filteredFavoriteCountries[index]; + final Country item = + _filteredFavoriteCountries[index]; return _buildCountryPickerItem(item); }, childCount: _filteredFavoriteCountries.length, @@ -154,10 +159,12 @@ class _CountryPickerDialogState extends State { void search(String value) { _filteredCountries = widget.countryList .stringSearch(value) - .where((item) => widget.favorite.any((code) => item.code != code)) + .where((item) => !widget.favorite.contains(item.code)) .toList() ..sort( - (a, b) => a.localizedName(widget.languageCode).compareTo(b.localizedName(widget.languageCode)), + (a, b) => a + .localizedName(widget.languageCode) + .compareTo(b.localizedName(widget.languageCode)), ); _filteredFavoriteCountries = _favoriteCountries.stringSearch(value); } @@ -179,11 +186,13 @@ class _CountryPickerDialogState extends State { contentPadding: widget.style?.listTilePadding, title: Text( item.localizedName(widget.languageCode), - style: widget.style?.countryNameStyle ?? const TextStyle(fontWeight: FontWeight.w700), + style: widget.style?.countryNameStyle ?? + const TextStyle(fontWeight: FontWeight.w700), ), trailing: Text( '+${item.dialCode}', - style: widget.style?.countryCodeStyle ?? const TextStyle(fontWeight: FontWeight.w700), + style: widget.style?.countryCodeStyle ?? + const TextStyle(fontWeight: FontWeight.w700), ), onTap: () { _selectedCountry = item; diff --git a/pubspec.yaml b/pubspec.yaml index f3a6c468..194f1fad 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: intl_phone_field description: A customised Flutter TextFormField to input international phone number along with country code. -version: 3.3.2 +version: 3.3.3 homepage: https://github.com/vanshg395/intl_phone_field environment: From 771f82470c0a91ddc6a98aad7bc5748e17a519d5 Mon Sep 17 00:00:00 2001 From: Abdalqader27 Date: Fri, 20 Dec 2024 14:46:27 +0400 Subject: [PATCH 8/8] fix: fixed search by country with by iso code --- example/.metadata | 24 ++++++- example/analysis_options.yaml | 28 +++++++++ example/android/.gitignore | 6 ++ example/android/app/build.gradle | 63 +++++++------------ .../android/app/src/debug/AndroidManifest.xml | 6 +- .../android/app/src/main/AndroidManifest.xml | 26 +++++--- .../com/example/example/MainActivity.kt | 6 -- .../intl_phone_field_example/MainActivity.kt | 3 +- .../res/drawable-v21/launch_background.xml | 12 ++++ .../app/src/main/res/values-night/styles.xml | 4 +- .../app/src/main/res/values/styles.xml | 12 ++-- .../app/src/profile/AndroidManifest.xml | 6 +- example/android/build.gradle | 19 +----- example/android/gradle.properties | 8 +-- .../gradle/wrapper/gradle-wrapper.properties | 3 +- example/android/settings.gradle | 30 ++++++--- example/lib/main.dart | 4 +- example/pubspec.lock | 42 ++++++------- example/test/widget_test.dart.OBSOLETE | 30 --------- lib/phone_number.dart | 32 +++++++--- pubspec.lock | 48 +++++++------- pubspec.yaml | 2 +- 22 files changed, 218 insertions(+), 196 deletions(-) create mode 100644 example/analysis_options.yaml delete mode 100644 example/android/app/src/main/kotlin/com/example/example/MainActivity.kt create mode 100644 example/android/app/src/main/res/drawable-v21/launch_background.xml delete mode 100644 example/test/widget_test.dart.OBSOLETE diff --git a/example/.metadata b/example/.metadata index 6ac2303d..8af9f156 100644 --- a/example/.metadata +++ b/example/.metadata @@ -4,7 +4,27 @@ # This file should be version controlled and should not be manually edited. version: - revision: f7a6a7906be96d2288f5d63a5a54c515a6e987fe - channel: stable + revision: "17025dd88227cd9532c33fa78f5250d548d87e9a" + channel: "stable" project_type: app + +# Tracks metadata for the flutter migrate command +migration: + platforms: + - platform: root + create_revision: 17025dd88227cd9532c33fa78f5250d548d87e9a + base_revision: 17025dd88227cd9532c33fa78f5250d548d87e9a + - platform: android + create_revision: 17025dd88227cd9532c33fa78f5250d548d87e9a + base_revision: 17025dd88227cd9532c33fa78f5250d548d87e9a + + # User provided section + + # List of Local paths (relative to this file) that should be + # ignored by the migrate tool. + # + # Files that are not part of the templates will be ignored by default. + unmanaged_files: + - 'lib/main.dart' + - 'ios/Runner.xcodeproj/project.pbxproj' diff --git a/example/analysis_options.yaml b/example/analysis_options.yaml new file mode 100644 index 00000000..0d290213 --- /dev/null +++ b/example/analysis_options.yaml @@ -0,0 +1,28 @@ +# This file configures the analyzer, which statically analyzes Dart code to +# check for errors, warnings, and lints. +# +# The issues identified by the analyzer are surfaced in the UI of Dart-enabled +# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be +# invoked from the command line by running `flutter analyze`. + +# The following line activates a set of recommended lints for Flutter apps, +# packages, and plugins designed to encourage good coding practices. +include: package:flutter_lints/flutter.yaml + +linter: + # The lint rules applied to this project can be customized in the + # section below to disable rules from the `package:flutter_lints/flutter.yaml` + # included above or to enable additional rules. A list of all available lints + # and their documentation is published at https://dart.dev/lints. + # + # Instead of disabling a lint rule for the entire project in the + # section below, it can also be suppressed for a single line of code + # or a specific dart file by using the `// ignore: name_of_lint` and + # `// ignore_for_file: name_of_lint` syntax on the line or in the file + # producing the lint. + rules: + # avoid_print: false # Uncomment to disable the `avoid_print` rule + # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule + +# Additional information about this file can be found at +# https://dart.dev/guides/language/analysis-options diff --git a/example/android/.gitignore b/example/android/.gitignore index bc2100d8..55afd919 100644 --- a/example/android/.gitignore +++ b/example/android/.gitignore @@ -5,3 +5,9 @@ gradle-wrapper.jar /gradlew.bat /local.properties GeneratedPluginRegistrant.java + +# Remember to never publicly share your keystore. +# See https://flutter.dev/to/reference-keystore +key.properties +**/*.keystore +**/*.jks diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 3bafe1b1..d1a34de0 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -1,63 +1,44 @@ -def localProperties = new Properties() -def localPropertiesFile = rootProject.file('local.properties') -if (localPropertiesFile.exists()) { - localPropertiesFile.withReader('UTF-8') { reader -> - localProperties.load(reader) - } -} - -def flutterRoot = localProperties.getProperty('flutter.sdk') -if (flutterRoot == null) { - throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") -} - -def flutterVersionCode = localProperties.getProperty('flutter.versionCode') -if (flutterVersionCode == null) { - flutterVersionCode = '1' +plugins { + id "com.android.application" + id "kotlin-android" + // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins. + id "dev.flutter.flutter-gradle-plugin" } -def flutterVersionName = localProperties.getProperty('flutter.versionName') -if (flutterVersionName == null) { - flutterVersionName = '1.0' -} - -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" - android { - compileSdkVersion 32 + namespace = "com.example.intl_phone_field_example" + compileSdk = flutter.compileSdkVersion + ndkVersion = flutter.ndkVersion - sourceSets { - main.java.srcDirs += 'src/main/kotlin' + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 } - lintOptions { - disable 'InvalidPackage' + kotlinOptions { + jvmTarget = JavaVersion.VERSION_1_8 } defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). - applicationId "com.example.intl_phone_field_example" - minSdkVersion flutter.minSdkVersion - targetSdkVersion 32 - versionCode flutterVersionCode.toInteger() - versionName flutterVersionName + applicationId = "com.example.intl_phone_field_example" + // You can update the following values to match your application needs. + // For more information, see: https://flutter.dev/to/review-gradle-config. + minSdk = flutter.minSdkVersion + targetSdk = flutter.targetSdkVersion + versionCode = flutter.versionCode + versionName = flutter.versionName } buildTypes { release { // TODO: Add your own signing config for the release build. // Signing with the debug keys for now, so `flutter run --release` works. - signingConfig signingConfigs.debug + signingConfig = signingConfigs.debug } } } flutter { - source '../..' -} - -dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + source = "../.." } diff --git a/example/android/app/src/debug/AndroidManifest.xml b/example/android/app/src/debug/AndroidManifest.xml index a6ec361e..399f6981 100644 --- a/example/android/app/src/debug/AndroidManifest.xml +++ b/example/android/app/src/debug/AndroidManifest.xml @@ -1,6 +1,6 @@ - - diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index c8552e08..8afa5c08 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -1,22 +1,17 @@ - - + + android:windowSoftInputMode="adjustResize"> + + + + + + diff --git a/example/android/app/src/main/kotlin/com/example/example/MainActivity.kt b/example/android/app/src/main/kotlin/com/example/example/MainActivity.kt deleted file mode 100644 index e793a000..00000000 --- a/example/android/app/src/main/kotlin/com/example/example/MainActivity.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.example.example - -import io.flutter.embedding.android.FlutterActivity - -class MainActivity: FlutterActivity() { -} diff --git a/example/android/app/src/main/kotlin/com/example/intl_phone_field_example/MainActivity.kt b/example/android/app/src/main/kotlin/com/example/intl_phone_field_example/MainActivity.kt index 1b47577d..2ae7708e 100644 --- a/example/android/app/src/main/kotlin/com/example/intl_phone_field_example/MainActivity.kt +++ b/example/android/app/src/main/kotlin/com/example/intl_phone_field_example/MainActivity.kt @@ -2,5 +2,4 @@ package com.example.intl_phone_field_example import io.flutter.embedding.android.FlutterActivity -class MainActivity: FlutterActivity() { -} +class MainActivity: FlutterActivity() diff --git a/example/android/app/src/main/res/drawable-v21/launch_background.xml b/example/android/app/src/main/res/drawable-v21/launch_background.xml new file mode 100644 index 00000000..f74085f3 --- /dev/null +++ b/example/android/app/src/main/res/drawable-v21/launch_background.xml @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/example/android/app/src/main/res/values-night/styles.xml b/example/android/app/src/main/res/values-night/styles.xml index 449a9f93..06952be7 100644 --- a/example/android/app/src/main/res/values-night/styles.xml +++ b/example/android/app/src/main/res/values-night/styles.xml @@ -3,14 +3,14 @@ - diff --git a/example/android/app/src/profile/AndroidManifest.xml b/example/android/app/src/profile/AndroidManifest.xml index a6ec361e..399f6981 100644 --- a/example/android/app/src/profile/AndroidManifest.xml +++ b/example/android/app/src/profile/AndroidManifest.xml @@ -1,6 +1,6 @@ - - diff --git a/example/android/build.gradle b/example/android/build.gradle index f87c9520..d2ffbffa 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -1,29 +1,16 @@ -buildscript { - ext.kotlin_version = '1.6.10' - repositories { - google() - jcenter() - } - - dependencies { - classpath 'com.android.tools.build:gradle:4.2.0' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - } -} - allprojects { repositories { google() - jcenter() + mavenCentral() } } -rootProject.buildDir = '../build' +rootProject.buildDir = "../build" subprojects { project.buildDir = "${rootProject.buildDir}/${project.name}" } subprojects { - project.evaluationDependsOn(':app') + project.evaluationDependsOn(":app") } tasks.register("clean", Delete) { diff --git a/example/android/gradle.properties b/example/android/gradle.properties index ca130d67..25971708 100644 --- a/example/android/gradle.properties +++ b/example/android/gradle.properties @@ -1,9 +1,3 @@ -org.gradle.jvmargs=-Xmx1536M \ ---add-exports=java.base/sun.nio.ch=ALL-UNNAMED \ ---add-opens=java.base/java.lang=ALL-UNNAMED \ ---add-opens=java.base/java.lang.reflect=ALL-UNNAMED \ ---add-opens=java.base/java.io=ALL-UNNAMED \ ---add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED -android.enableR8=true +org.gradle.jvmargs=-Xmx4G -XX:MaxMetaspaceSize=2G -XX:+HeapDumpOnOutOfMemoryError android.useAndroidX=true android.enableJetifier=true diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties index 595fb867..7bb2df6b 100644 --- a/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/example/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Fri Jun 23 08:50:38 CEST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip diff --git a/example/android/settings.gradle b/example/android/settings.gradle index 5a2f14fb..b9e43bd3 100644 --- a/example/android/settings.gradle +++ b/example/android/settings.gradle @@ -1,15 +1,25 @@ -include ':app' +pluginManagement { + def flutterSdkPath = { + def properties = new Properties() + file("local.properties").withInputStream { properties.load(it) } + def flutterSdkPath = properties.getProperty("flutter.sdk") + assert flutterSdkPath != null, "flutter.sdk not set in local.properties" + return flutterSdkPath + }() -def flutterProjectRoot = rootProject.projectDir.parentFile.toPath() + includeBuild("$flutterSdkPath/packages/flutter_tools/gradle") -def plugins = new Properties() -def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins') -if (pluginsFile.exists()) { - pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) } + repositories { + google() + mavenCentral() + gradlePluginPortal() + } } -plugins.each { name, path -> - def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile() - include ":$name" - project(":$name").projectDir = pluginDirectory +plugins { + id "dev.flutter.flutter-plugin-loader" version "1.0.0" + id "com.android.application" version "8.1.0" apply false + id "org.jetbrains.kotlin.android" version "1.8.22" apply false } + +include ":app" diff --git a/example/lib/main.dart b/example/lib/main.dart index c825be30..40db7eed 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -54,7 +54,7 @@ class _MyAppState extends State { height: 10, ), IntlPhoneField( - favourite: ['AE','SA','LB'], + favourite: ['AE', 'SA', 'LB'], controller: controller, focusNode: focusNode, decoration: InputDecoration( @@ -63,7 +63,7 @@ class _MyAppState extends State { borderSide: BorderSide(), ), ), - languageCode: "en", + languageCode: "GB", onChanged: (phone) { print(phone.completeNumber); }, diff --git a/example/pubspec.lock b/example/pubspec.lock index 01bb0615..34244ea1 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -37,10 +37,10 @@ packages: dependency: transitive description: name: collection - sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + sha256: a1ace0a119f20aabc852d165077c036cd864315bd99b7eaa10a60100341941bf url: "https://pub.dev" source: hosted - version: "1.18.0" + version: "1.19.0" fake_async: dependency: transitive description: @@ -65,23 +65,23 @@ packages: path: ".." relative: true source: path - version: "3.3.2" + version: "3.3.4" leak_tracker: dependency: transitive description: name: leak_tracker - sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a" + sha256: "7bb2830ebd849694d1ec25bf1f44582d6ac531a57a365a803a6034ff751d2d06" url: "https://pub.dev" source: hosted - version: "10.0.4" + version: "10.0.7" leak_tracker_flutter_testing: dependency: transitive description: name: leak_tracker_flutter_testing - sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8" + sha256: "9491a714cca3667b60b5c420da8217e6de0d1ba7a5ec322fab01758f6998f379" url: "https://pub.dev" source: hosted - version: "3.0.3" + version: "3.0.8" leak_tracker_testing: dependency: transitive description: @@ -102,18 +102,18 @@ packages: dependency: transitive description: name: material_color_utilities - sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" + sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec url: "https://pub.dev" source: hosted - version: "0.8.0" + version: "0.11.1" meta: dependency: transitive description: name: meta - sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136" + sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7 url: "https://pub.dev" source: hosted - version: "1.12.0" + version: "1.15.0" path: dependency: transitive description: @@ -126,7 +126,7 @@ packages: dependency: transitive description: flutter source: sdk - version: "0.0.99" + version: "0.0.0" source_span: dependency: transitive description: @@ -139,10 +139,10 @@ packages: dependency: transitive description: name: stack_trace - sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + sha256: "9f47fd3630d76be3ab26f0ee06d213679aa425996925ff3feffdec504931c377" url: "https://pub.dev" source: hosted - version: "1.11.1" + version: "1.12.0" stream_channel: dependency: transitive description: @@ -155,10 +155,10 @@ packages: dependency: transitive description: name: string_scanner - sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + sha256: "688af5ed3402a4bde5b3a6c15fd768dbf2621a614950b17f04626c431ab3c4c3" url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.3.0" term_glyph: dependency: transitive description: @@ -171,10 +171,10 @@ packages: dependency: transitive description: name: test_api - sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" + sha256: "664d3a9a64782fcdeb83ce9c6b39e78fd2971d4e37827b9b06c3aa1edc5e760c" url: "https://pub.dev" source: hosted - version: "0.7.0" + version: "0.7.3" vector_math: dependency: transitive description: @@ -187,10 +187,10 @@ packages: dependency: transitive description: name: vm_service - sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec" + sha256: f6be3ed8bd01289b34d679c2b62226f63c0e69f9fd2e50a6b3c1c729a961041b url: "https://pub.dev" source: hosted - version: "14.2.1" + version: "14.3.0" sdks: - dart: ">=3.3.0 <4.0.0" + dart: ">=3.4.0 <4.0.0" flutter: ">=3.18.0-18.0.pre.54" diff --git a/example/test/widget_test.dart.OBSOLETE b/example/test/widget_test.dart.OBSOLETE deleted file mode 100644 index 747db1da..00000000 --- a/example/test/widget_test.dart.OBSOLETE +++ /dev/null @@ -1,30 +0,0 @@ -// This is a basic Flutter widget test. -// -// To perform an interaction with a widget in your test, use the WidgetTester -// utility that Flutter provides. For example, you can send tap and scroll -// gestures. You can also use WidgetTester to find child widgets in the widget -// tree, read text, and verify that the values of widget properties are correct. - -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; - -import 'package:example/main.dart'; - -void main() { - testWidgets('Counter increments smoke test', (WidgetTester tester) async { - // Build our app and trigger a frame. - await tester.pumpWidget(MyApp()); - - // Verify that our counter starts at 0. - expect(find.text('0'), findsOneWidget); - expect(find.text('1'), findsNothing); - - // Tap the '+' icon and trigger a frame. - await tester.tap(find.byIcon(Icons.add)); - await tester.pump(); - - // Verify that our counter has incremented. - expect(find.text('0'), findsNothing); - expect(find.text('1'), findsOneWidget); - }); -} diff --git a/lib/phone_number.dart b/lib/phone_number.dart index 912cb07c..0861739e 100644 --- a/lib/phone_number.dart +++ b/lib/phone_number.dart @@ -4,6 +4,8 @@ class NumberTooLongException implements Exception {} class NumberTooShortException implements Exception {} +class CountryCodeTooShortException implements Exception {} + class InvalidCharactersException implements Exception {} class PhoneNumber { @@ -26,12 +28,16 @@ class PhoneNumber { Country country = getCountry(completeNumber); String number; if (completeNumber.startsWith('+')) { - number = completeNumber.substring(1 + country.dialCode.length + country.regionCode.length); + number = completeNumber + .substring(1 + country.dialCode.length + country.regionCode.length); } else { - number = completeNumber.substring(country.dialCode.length + country.regionCode.length); + number = completeNumber + .substring(country.dialCode.length + country.regionCode.length); } return PhoneNumber( - countryISOCode: country.code, countryCode: country.dialCode + country.regionCode, number: number); + countryISOCode: country.code, + countryCode: country.dialCode + country.regionCode, + number: number); } on InvalidCharactersException { rethrow; // ignore: unused_catch_clause @@ -41,7 +47,7 @@ class PhoneNumber { } bool isValidNumber() { - Country country = getCountry(completeNumber); + Country country = getCountryByCountryCode(countryISOCode); if (number.length < country.minLength) { throw NumberTooShortException(); } @@ -68,12 +74,22 @@ class PhoneNumber { } if (phoneNumber.startsWith('+')) { - return countries - .firstWhere((country) => phoneNumber.substring(1).startsWith(country.dialCode + country.regionCode)); + return countries.firstWhere((country) => phoneNumber + .substring(1) + .startsWith(country.dialCode + country.regionCode)); + } + return countries.firstWhere((country) => + phoneNumber.startsWith(country.dialCode + country.regionCode)); + } + + static Country getCountryByCountryCode(String countryIsoCode) { + if (countryIsoCode == "") { + throw CountryCodeTooShortException(); } - return countries.firstWhere((country) => phoneNumber.startsWith(country.dialCode + country.regionCode)); + return countries.firstWhere((country) => countryIsoCode == country.code); } @override - String toString() => 'PhoneNumber(countryISOCode: $countryISOCode, countryCode: $countryCode, number: $number)'; + String toString() => + 'PhoneNumber(countryISOCode: $countryISOCode, countryCode: $countryCode, number: $number)'; } diff --git a/pubspec.lock b/pubspec.lock index ae902ef2..eaf53d19 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -61,10 +61,10 @@ packages: dependency: transitive description: name: collection - sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + sha256: a1ace0a119f20aabc852d165077c036cd864315bd99b7eaa10a60100341941bf url: "https://pub.dev" source: hosted - version: "1.18.0" + version: "1.19.0" convert: dependency: transitive description: @@ -175,18 +175,18 @@ packages: dependency: transitive description: name: leak_tracker - sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a" + sha256: "7bb2830ebd849694d1ec25bf1f44582d6ac531a57a365a803a6034ff751d2d06" url: "https://pub.dev" source: hosted - version: "10.0.4" + version: "10.0.7" leak_tracker_flutter_testing: dependency: transitive description: name: leak_tracker_flutter_testing - sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8" + sha256: "9491a714cca3667b60b5c420da8217e6de0d1ba7a5ec322fab01758f6998f379" url: "https://pub.dev" source: hosted - version: "3.0.3" + version: "3.0.8" leak_tracker_testing: dependency: transitive description: @@ -223,18 +223,18 @@ packages: dependency: transitive description: name: material_color_utilities - sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" + sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec url: "https://pub.dev" source: hosted - version: "0.8.0" + version: "0.11.1" meta: dependency: transitive description: name: meta - sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136" + sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7 url: "https://pub.dev" source: hosted - version: "1.12.0" + version: "1.15.0" mime: dependency: transitive description: @@ -319,7 +319,7 @@ packages: dependency: transitive description: flutter source: sdk - version: "0.0.99" + version: "0.0.0" source_map_stack_trace: dependency: transitive description: @@ -348,10 +348,10 @@ packages: dependency: transitive description: name: stack_trace - sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + sha256: "9f47fd3630d76be3ab26f0ee06d213679aa425996925ff3feffdec504931c377" url: "https://pub.dev" source: hosted - version: "1.11.1" + version: "1.12.0" stream_channel: dependency: transitive description: @@ -364,10 +364,10 @@ packages: dependency: transitive description: name: string_scanner - sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + sha256: "688af5ed3402a4bde5b3a6c15fd768dbf2621a614950b17f04626c431ab3c4c3" url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.3.0" term_glyph: dependency: transitive description: @@ -380,26 +380,26 @@ packages: dependency: "direct dev" description: name: test - sha256: "7ee446762c2c50b3bd4ea96fe13ffac69919352bd3b4b17bac3f3465edc58073" + sha256: "713a8789d62f3233c46b4a90b174737b2c04cb6ae4500f2aa8b1be8f03f5e67f" url: "https://pub.dev" source: hosted - version: "1.25.2" + version: "1.25.8" test_api: dependency: transitive description: name: test_api - sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" + sha256: "664d3a9a64782fcdeb83ce9c6b39e78fd2971d4e37827b9b06c3aa1edc5e760c" url: "https://pub.dev" source: hosted - version: "0.7.0" + version: "0.7.3" test_core: dependency: transitive description: name: test_core - sha256: "2bc4b4ecddd75309300d8096f781c0e3280ca1ef85beda558d33fcbedc2eead4" + sha256: "12391302411737c176b0b5d6491f466b0dd56d4763e347b6714efbaa74d7953d" url: "https://pub.dev" source: hosted - version: "0.6.0" + version: "0.6.5" typed_data: dependency: transitive description: @@ -420,10 +420,10 @@ packages: dependency: transitive description: name: vm_service - sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec" + sha256: f6be3ed8bd01289b34d679c2b62226f63c0e69f9fd2e50a6b3c1c729a961041b url: "https://pub.dev" source: hosted - version: "14.2.1" + version: "14.3.0" watcher: dependency: transitive description: @@ -457,5 +457,5 @@ packages: source: hosted version: "3.1.2" sdks: - dart: ">=3.3.0 <4.0.0" + dart: ">=3.4.0 <4.0.0" flutter: ">=3.18.0-18.0.pre.54" diff --git a/pubspec.yaml b/pubspec.yaml index 194f1fad..add3e8a6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: intl_phone_field description: A customised Flutter TextFormField to input international phone number along with country code. -version: 3.3.3 +version: 3.3.4 homepage: https://github.com/vanshg395/intl_phone_field environment: