daniel-ioannou / flutter_country_picker Goto Github PK
View Code? Open in Web Editor NEWA flutter package to select a country from a list of countries.
Home Page: https://pub.dev/packages/country_picker
License: MIT License
A flutter package to select a country from a list of countries.
Home Page: https://pub.dev/packages/country_picker
License: MIT License
I came across an issue.....The screen overflow when searching a particular country !
First of all, thank you for your great job.
I would like to add French (fr) language support, is it possible and what is the best way to do it?
Is it possible to initially have focus on search bar, with virtual keyboard up?
Hi! Thanks for your great package! I was wondering if it was possible to extract the flag image once a country is selected? Thanks!
If the country is parsed from .parse(...)
or .tryParse()
accessing nameLocalized
throws a LateInitialisationError.
Probably not an easy fix since a context is needed to get the localized name but maybe there is a way to do it.
country_picker: ^2.0.22
======== Exception caught by image resource service ================================================
The following Event$ object was thrown resolving an image frame:
[object Event]
I am able to see that the context has the appropriate language before calling the showCountryPicker function,
but within the CountryListView widget, I am no longer able to access the context.
I saw this by printing ${CountryLocalizations.of(context)?.countryName(countryCode: 'GB')
before the call and receiving the correct value.
when I try printing this same value within the CountryListView widget , it prints a null value.
What am I doing wrong or is there an error ?
Thanks,
Hello,
I'm using the country picker as follows:
GestureDetector( child: Icon(Icons.edit), onTap: () { showCountryPicker( context: context, onSelect: (Country country) { setState(() { currentCountry = country.displayNameNoCountryCode; }); }, ); }, )
When the country picker is shown, the width cannot be set so it takes the whole monitor screen size
Please, there is an error in nomination of Morocco in French
Morocco is Maroc in French not Moroc, can I control the nomination?
Hello maintainers!
The country name translation and localizations are done very well in the package. But I couldn't find the country name localizations for most of the Asian countries [🇳🇵, 🇮🇳, 🇧🇹, 🇵🇰, 🇧🇩 ] including mine.
It would be much better to configure the localization feature for Asian countries too.
:)
Country names are always ordered using their english names.
If the application uses another locale and shows the country names in a different language, the order of the countries is the same as if using english, with the result that the list shown is not ordered correctly.
I have a user profile with his mobile number and want to show the ( flag +XX ) next to it.
but I'm not able to get the country object before the selection
can you help me with that please..
I will make a PR with null safety support implementation
I'm trying to store the name of the country in both Arabic and English,
I did setup supportedLocales and localizationsDelegates in MaterialApp,
when the app is set to Arabic local, getting the value with: "country.name" gives English name
and getting the value with: country.getTranslatedName(context) gives Arabic name, so that works, but if the app is in English local
both methods gives English name,
what should I do to get both English and Arabic name of the country when the app is in English local?
When the locale is not supported, the plugin not return the deault one (english).
The returned value is null.
/development/flutter/.pub-cache/git/country_pickers-f71243f09a21c9816b698c0b52c53ea9ce4e4779/lib/utils/my_alert_dialog.dart:108:46: Error: The getter 'title' isn't defined for the class 'TextTheme'.
FAILURE: Build failed with an exception.
flutter doctor -v
[✓] Flutter (Channel stable, 2.5.3, on Mac OS X 10.15.7 19H15 darwin-x64, locale en-US)
• Flutter version 2.5.3 at /Users/xxxx/development/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 18116933e7 (5 days ago), 2021-10-15 10:46:35 -0700
• Engine revision d3ea636dc5
• Dart version 2.14.4
Is there a way to select multiple country items before the dialog is closed?
Following the example of a old similar library, you can add static methods
country_pickers
Example
Country _selectedDialogCountry = CountryPickerUtils.Utils.getCountryByIsoCode('MF');
void _openCountryPickerDialog() => showCountryPicker(
context: context,
//Optional. Can be used to exclude(remove) one ore more country from the countries list (optional).
// exclude: <String>['KN', 'MF'],
favorite: <String>['SE, US'],
//Optional. Shows phone code before the country name.
showPhoneCode: true,
onSelect: (Country country) {
setState(() => _selectedDialogCountry = country);
},
// Optional. Sets the theme for the country list picker.
countryListTheme: CountryListThemeData(
// Optional. Sets the border radius for the bottomsheet.
borderRadius: BorderRadius.only(
topLeft: Radius.circular(40.0),
topRight: Radius.circular(40.0),
),
// Optional. Styles the search field.
inputDecoration: InputDecoration(
labelText: 'Search',
hintText: 'Start typing to search',
prefixIcon: const Icon(Icons.search),
border: OutlineInputBorder(
borderSide: BorderSide(
color: const Color(0xFF8C98A8).withOpacity(0.2),
),
),
),
),
);
Text("+${_selectedDialogCountry.phoneCode}"), -> view user
change utils
import 'country.dart';
import 'res/country_codes.dart';
class Utils {
static List<Country> _countryList = countryCodes.map((country) => Country.from(json: country)).toList();
static String countryCodeToEmoji(String countryCode) {
// 0x41 is Letter A
// 0x1F1E6 is Regional Indicator Symbol Letter A
// Example :
// firstLetter U => 20 + 0x1F1E6
// secondLetter S => 18 + 0x1F1E6
// See: https://en.wikipedia.org/wiki/Regional_Indicator_Symbol
final int firstLetter = countryCode.codeUnitAt(0) - 0x41 + 0x1F1E6;
final int secondLetter = countryCode.codeUnitAt(1) - 0x41 + 0x1F1E6;
return String.fromCharCode(firstLetter) + String.fromCharCode(secondLetter);
}
static Country getCountryByIsoCode(String isoCode) {
try {
return _countryList.firstWhere((country) => country.countryCode.toLowerCase() == isoCode.toLowerCase(),
);
} catch (error) {
throw Exception("The initialValue provided is not a supported iso code!");
}
}
}
Originally posted by kuyucuburak January 10, 2022
Hi, country code of US should be US
not ABD
. Country code should not be changed according to localizations. The others seems unchanged. It seems this is just a bug. Right?
'BT' code is duplicate in tr.dart
The second BT
should be IT
we want mobile number length based on country like example if it India it has 10 digits so it will be useful for use restrict textfield lengths based on country
Currently there is no option to disable the country picker dropdown. In case if I have missed the doc, please point me to the same.
help wit hthat
How can i get the Flag Image
Hi!
I was wondering if there are any plans to add this feature for 3 digit country codes?
If not, I can gladly give it a shot.
Is it possible to extend this project and also provide a language picker?
The use case is to provide flutter app translation support by selecting a language from the picker
This expression has a type of 'void' so its value can't be used.
Try checking to see if you're using the correct API; there might be a function or call that returns void you didn't expect. Also check type parameters and variables which might also be void.dartuse_of_void_result
I get this error when I added
showCountryPicker(
context: context,
onSelect: (Country country) {
if (kDebugMode) {
print('Select country: ${country.displayName}');
}
},
),
I am building a windows application that utilizes country pickers. My code is as follows:
class _CountryPickerButton extends StatefulWidget {
const _CountryPickerButton();
@override
State<_CountryPickerButton> createState() => _CountryPickerButtonState();
}
class _CountryPickerButtonState extends State<_CountryPickerButton> {
Country selectedCountry = Country.parse('Syria');
@override
Widget build(BuildContext context) {
return TextFormField(
maxLength: 10,
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
keyboardType: TextInputType.number,
decoration: InputDecoration(
prefix: _buildPhoneButton(context),
labelText: 'phone number',
border: const OutlineInputBorder(),
),
);
}
Widget _buildPhoneButton(BuildContext context) {
return TextButton(
child: Text('+${selectedCountry.phoneCode}'),
onPressed: () => showCountryPicker(
context: context,
onSelect: (country) => setState(() => selectedCountry = country),
),
);
}
}
It's working okay on Android emulators:
On windows, however, it's showing letters instead of flags:
Right now it's impossible to define custom colors for the pop-up
Hi. I've made an app that uses localizations, as described in the Flutter docs. I've tried to run the example project, and that implementation works. However, when implemented using the official Flutter guide, it doesn't work. I've added a complete runnable project that demonstrates this issue.
Other localized strings works as intended , but the static CountryLocalizations? of(BuildContext context)
method in country_localizations.dart
returns null, which means that none of the strings in the package are translated. I'm not completely sure what causes this issue, because the inner workings of the Flutter localizations still remains a mystery to me.
An example of a workaround fould be to return CountryLocalizations(Localizations.localeOf(context))
instead of Localizations.of<CountryLocalizations>(context, CountryLocalizations)
, but I don't know if this comes with some kind of cost. Thoughts?
Swaziland country was officially renamed as Eswatini in 2018 (https://en.wikipedia.org/wiki/Eswatini)
Can I search by country code or currency?
Hi,
Is there an option to set default or preferred countries?
Thanks
The utils/my_alert_dialog.dart file is using the constructor ButtonTheme.bar and it is deprecated now. It should be updated to ButtonBarTheme.
How can i set Initial Country in textfield ? For eg. I have to fetch Country from API then i must have to pass some CountryCode arguments!!!!
Hi Daniel,
Would it be possible to add Latinized search by country name?
The https://pub.dev/packages/latinize is a good option to "to convert accents (diacritics) from strings to latin characters" before search.
I've forked and implemented using latinize: ^0.1.0-nullsafety.0. It is doing good here!
The fork is at https://github.com/cc-nogueira/flutter_country_picker.
Thanks.
is it possible to get Country object by passing country code?
e.g. after picking a country, i have some data like country code, and name.
now, how do I get (later) that very same object just by country code? without opening the picker, of course
Country country;
(country.phoneCode) provides us the country code but it doesn't provide us the + sign and we have to write it manually in our code
Please add 'style' to the text search field
So I can add custom style to the search text field (color, font)
Thank you for creating a very easy to implement Country Picker for Flutter.
I made showPhoneCode: false, and it does not display the phone code on the drop down list; however, it posts that data back to the context; United States (US) [+1], and I would rather have it show just show the Country when posting back after selection. Would it be possible to select only the country name from country.displayname?
Thanks again.
How to set the name of a country to follow the international language settings inside the app by default instead of following the system
Hi,
Great package but could you tell me if you plan to improve display by making the bottom sheet with adaptive height to content or at least being able to set the height to a specific height?
Hi,
Would it be possible to have the the code to import a .json file instead of a list of countries, without the flag?
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.