Closed sinhpn92 closed 1 year ago
Hello ππ»
You can access the flagUri
as a property of a CountryCode
object.
Example:
GestureDetector(
onTap: () async {
// Show the country code picker when tapped.
final code = await countryPicker.showPicker(context: context);
// Null check
if (code != null) {
print(code);
// Access flagUri property.
print(code.flagUri);
}
},
/// Some omitted values.
Hello ππ» You can access the
flagUri
as a property of aCountryCode
object. Example:GestureDetector( onTap: () async { // Show the country code picker when tapped. final code = await countryPicker.showPicker(context: context); // Null check if (code != null) print(code); // Access flagUri property. print(code.flagUri); }, /// Some omitted values.
Thank you so much. I got it. I have installed wrong version :d
Now I got error Null check operator used on a null value
. Can you please help? @fernan542 Thank you
That error means that the code
is null
or the user didn't select from the picker.
In order to solve that, you need to check if the code
is not null before you use it or any of the property.
// Check if not null first.
if (code != null) {
// Here you're confident that code is not null,
// you can access its properties.
print(code.flagUri);
}
Another thing, in order to help you more, I suggest you paste your code and I'll check it. βΊοΈ I edited my answer above because I forgot to add curly braces. Thanks!
Thank you @fernan542
This is my code to call the picker:
Future<void> _onFlagPressed() async {
const countryPicker = FlCountryCodePicker();
final code = await countryPicker.showPicker(context: context);
if (code == null) return;
setState(() {
_countryCode = code;
});
}
And the picker dialog showing up, then I get the error:
What version are you using? Can you show the full error log at your console?
@fernan542 This my version: phone_number: ^2.0.0
Error log here:
Have you tried adding the localizations in your MaterialApp
?
First, import the package and add an alias to prevent other import errors.
import 'package:fl_country_code_picker/fl_country_code_picker.dart' as flc;
Then add the following values at your app's MaterialApp:
MaterialApp(
title: 'Your App',
// Supported locales at the moment.
// Cannot find your locale? Please make a request.
supportedLocales: flc.supportedLocales.map((e) => Locale(e)),
localizationsDelegates: const [
// Package's localization delegate.
CountryLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
// ... some omitted values
);
ok got it. It's working now. Thank you so much @fernan542
You're always welcome. Thank you for using my package!
Hi,
I have got error
The getter 'flagUri' isn't defined for the type 'CountryCode'.
when try to use custom flag image. Have any missing here?Thank you.