diff --git a/example/pubspec.lock b/example/pubspec.lock index aa66e30c..5261a691 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,39 +65,63 @@ packages: path: ".." relative: true source: path - version: "3.2.0" + version: "3.3.0" + leak_tracker: + dependency: transitive + description: + name: leak_tracker + sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05" + url: "https://pub.dev" + source: hosted + version: "10.0.5" + leak_tracker_flutter_testing: + dependency: transitive + description: + name: leak_tracker_flutter_testing + sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806" + url: "https://pub.dev" + source: hosted + version: "3.0.5" + 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: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec url: "https://pub.dev" source: hosted - version: "0.5.0" + version: "0.11.1" meta: dependency: transitive description: name: meta - sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" + sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7 url: "https://pub.dev" source: hosted - version: "1.9.1" + version: "1.15.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 @@ -115,18 +139,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 +171,10 @@ packages: dependency: transitive description: name: test_api - sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8" + sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb" url: "https://pub.dev" source: hosted - version: "0.6.0" + version: "0.7.2" 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: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10 + name: vm_service + sha256: f652077d0bdf60abe4c1f6377448e8655008eef28f128bc023f7b5e8dfeb48fc url: "https://pub.dev" source: hosted - version: "0.1.4-beta" + version: "14.2.4" sdks: - dart: ">=3.1.0-185.0.dev <4.0.0" + dart: ">=3.3.0 <4.0.0" + flutter: ">=3.18.0-18.0.pre.54" diff --git a/lib/countries.dart b/lib/countries.dart index 73bc8d4e..be3eaaca 100644 --- a/lib/countries.dart +++ b/lib/countries.dart @@ -3502,7 +3502,7 @@ const List countries = [ flag: "🇰🇪", code: "KE", dialCode: "254", - minLength: 10, + minLength: 9, maxLength: 10, ), Country( diff --git a/lib/intl_phone_field.dart b/lib/intl_phone_field.dart index a28ddafa..bc2abbb9 100644 --- a/lib/intl_phone_field.dart +++ b/lib/intl_phone_field.dart @@ -278,7 +278,8 @@ class IntlPhoneField extends StatefulWidget { this.inputFormatters, this.enabled = true, this.keyboardAppearance, - @Deprecated('Use searchFieldInputDecoration of PickerDialogStyle instead') this.searchText = 'Search country', + @Deprecated('Use searchFieldInputDecoration of PickerDialogStyle instead') + this.searchText = 'Search country', this.dropdownIconPosition = IconPosition.leading, this.dropdownIcon = const Icon(Icons.arrow_drop_down), this.autofocus = false, @@ -319,20 +320,25 @@ class _IntlPhoneFieldState extends State { if (widget.initialCountryCode == null && number.startsWith('+')) { number = number.substring(1); // parse initial value - _selectedCountry = countries.firstWhere((country) => number.startsWith(country.fullCountryCode), + _selectedCountry = countries.firstWhere( + (country) => number.startsWith(country.fullCountryCode), orElse: () => _countryList.first); // remove country code from the initial number value - number = number.replaceFirst(RegExp("^${_selectedCountry.fullCountryCode}"), ""); + number = number.replaceFirst( + RegExp("^${_selectedCountry.fullCountryCode}"), ""); } else { - _selectedCountry = _countryList.firstWhere((item) => item.code == (widget.initialCountryCode ?? 'US'), + _selectedCountry = _countryList.firstWhere( + (item) => item.code == (widget.initialCountryCode ?? 'US'), orElse: () => _countryList.first); // remove country code from the initial number value if (number.startsWith('+')) { - number = number.replaceFirst(RegExp("^\\+${_selectedCountry.fullCountryCode}"), ""); + number = number.replaceFirst( + RegExp("^\\+${_selectedCountry.fullCountryCode}"), ""); } else { - number = number.replaceFirst(RegExp("^${_selectedCountry.fullCountryCode}"), ""); + number = number.replaceFirst( + RegExp("^${_selectedCountry.fullCountryCode}"), ""); } } @@ -384,7 +390,9 @@ class _IntlPhoneFieldState extends State { return TextFormField( key: widget.formFieldKey, initialValue: (widget.controller == null) ? number : null, - autofillHints: widget.disableAutoFillHints ? null : [AutofillHints.telephoneNumberNational], + autofillHints: widget.disableAutoFillHints + ? null + : [AutofillHints.telephoneNumberNational], readOnly: widget.readOnly, obscureText: widget.obscureText, textAlign: widget.textAlign, @@ -408,7 +416,8 @@ class _IntlPhoneFieldState extends State { widget.onSaved?.call( PhoneNumber( countryISOCode: _selectedCountry.code, - countryCode: '+${_selectedCountry.dialCode}${_selectedCountry.regionCode}', + countryCode: + '+${_selectedCountry.dialCode}${_selectedCountry.regionCode}', number: value!, ), ); @@ -429,14 +438,24 @@ class _IntlPhoneFieldState extends State { validator: (value) { if (value == null || !isNumeric(value)) return validatorMessage; if (!widget.disableLengthCheck) { - return value.length >= _selectedCountry.minLength && value.length <= _selectedCountry.maxLength + // Special case for Kenya - accept either 9 or 10 digits + if (_selectedCountry.code == 'KE') { + return (value.length == 9 || value.length == 10) + ? null + : widget.invalidNumberMessage; + } + // Default behavior for other countries + return value.length == _selectedCountry.minLength || + value.length == _selectedCountry.maxLength ? null : widget.invalidNumberMessage; } - return validatorMessage; }, - maxLength: widget.disableLengthCheck ? null : _selectedCountry.maxLength, + // Update the `maxLength` in the TextFormField + maxLength: widget.disableLengthCheck + ? null + : (_selectedCountry.code == 'KE' ? 10 : _selectedCountry.maxLength), keyboardType: widget.keyboardType, inputFormatters: widget.inputFormatters, enabled: widget.enabled, diff --git a/pubspec.lock b/pubspec.lock index 9fad3df1..d43605c2 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -49,6 +49,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.3.0" + cli_config: + dependency: transitive + description: + name: cli_config + sha256: ac20a183a07002b700f0c25e61b7ee46b23c309d76ab7b7640a028f18e4d99ec + url: "https://pub.dev" + source: hosted + version: "0.2.0" clock: dependency: transitive description: @@ -61,10 +69,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: @@ -77,10 +85,10 @@ packages: dependency: transitive description: name: coverage - sha256: "2fb815080e44a09b85e0f2ca8a820b15053982b2e714b59267719e8a9ff17097" + sha256: "9086475ef2da7102a0c0a4e37e1e30707e7fb7b6d28c209f559a9c5f8ce42016" url: "https://pub.dev" source: hosted - version: "1.6.3" + version: "1.12.0" crypto: dependency: transitive description: @@ -171,6 +179,30 @@ packages: url: "https://pub.dev" source: hosted version: "0.6.7" + leak_tracker: + dependency: transitive + description: + name: leak_tracker + sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05" + url: "https://pub.dev" + source: hosted + version: "10.0.5" + leak_tracker_flutter_testing: + dependency: transitive + description: + name: leak_tracker_flutter_testing + sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806" + url: "https://pub.dev" + source: hosted + version: "3.0.5" + 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 +223,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: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec url: "https://pub.dev" source: hosted - version: "0.5.0" + version: "0.11.1" meta: dependency: transitive description: name: meta - sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" + sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7 url: "https://pub.dev" source: hosted - version: "1.9.1" + version: "1.15.0" mime: dependency: transitive description: @@ -239,10 +271,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: @@ -324,18 +356,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 +388,26 @@ packages: dependency: "direct dev" description: name: test - sha256: "13b41f318e2a5751c3169137103b60c584297353d4b1761b66029bae6411fe46" + sha256: "7ee44229615f8f642b68120165ae4c2a75fe77ae2065b1e55ae4711f6cf0899e" url: "https://pub.dev" source: hosted - version: "1.24.3" + version: "1.25.7" test_api: dependency: transitive description: name: test_api - sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8" + sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb" url: "https://pub.dev" source: hosted - version: "0.6.0" + version: "0.7.2" test_core: dependency: transitive description: name: test_core - sha256: "99806e9e6d95c7b059b7a0fc08f07fc53fabe54a829497f0d9676299f1e8637e" + sha256: "55ea5a652e38a1dfb32943a7973f3681a60f872f8c3a05a14664ad54ef9c6696" url: "https://pub.dev" source: hosted - version: "0.5.3" + version: "0.6.4" typed_data: dependency: transitive description: @@ -396,10 +428,10 @@ packages: dependency: transitive description: name: vm_service - sha256: ada49637c27973c183dad90beb6bd781eea4c9f5f955d35da172de0af7bd3440 + sha256: f652077d0bdf60abe4c1f6377448e8655008eef28f128bc023f7b5e8dfeb48fc url: "https://pub.dev" source: hosted - version: "11.8.0" + version: "14.2.4" watcher: dependency: transitive description: @@ -408,14 +440,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.1.0" - web: - dependency: transitive - description: - name: web - sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10 - url: "https://pub.dev" - source: hosted - version: "0.1.4-beta" web_socket_channel: dependency: transitive description: @@ -441,4 +465,5 @@ packages: source: hosted version: "3.1.2" sdks: - dart: ">=3.1.0-185.0.dev <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 70c8bc56..5a9237cc 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,7 +4,7 @@ version: 3.3.0 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: