By reading the documentation of riverpod I wanted to redo the example of the section "third party examples" the example is "firebase phone auth with riverpod" here is the link:https://docs-v2.riverpod.dev/docs/getting_started ; and the github repository is the following:https://github.com/julienlebren/flutter_firebase_phone_auth_riverpod; I would like to load the list of countries and their area code to be able to choose a country and enter a corresponding number but my code does not load anything.
I modified the code to comply with null safety and here is my github code in the authenticationWithProvider branch:https://github.com/jordanSinde/com_akdemix/tree/authenticationWithProvider; at compile time, the code does not display anything when loading the list of countries and their area codes so instead of having this enter image description here I rather have this enter image description here; here is the function which aims to load this list
Future<void> _loadCountries() async {
try {
await FlutterLibphonenumber().init();
var countries = CountryManager().countries;
countries.sort((a, b) {
return a.countryName!
.toLowerCase()
.compareTo(b.countryName!.toLowerCase());
});
countries = countries;
final langCode = ui.window.locale.languageCode.toUpperCase();
_firebaseAuth.setLanguageCode(langCode);
var filteredCountries =
countries.where((item) => item.countryCode == langCode);
if (filteredCountries.isEmpty) {
filteredCountries = countries.where((item) => item.countryCode == 'US');
}
if (filteredCountries.isEmpty) {
throw Exception('Unable to find a default country!');
}
setCountry(filteredCountries.first);
} catch (e) {
state = AuthState.error(e.toString());
}
}
void setCountry(CountryWithPhoneCode selectedCountry) {
_selectedCountry = selectedCountry;
state = AuthState.ready(selectedCountry);
}
Future<void> parsePhoneNumber(String inputText) async {
_phoneNumber = await FlutterLibphonenumber().parse(
"+${_selectedCountry.phoneCode}${inputText.replaceAll(RegExp(r'[^0-9]'), '')}",
region: _selectedCountry.countryCode,
);
if (_phoneNumber['type'] != 'mobile') {
throw Exception('You must enter a mobile phone number.');
}
}
the package used is flutter_libphonenumber; on the other hand the console does not show me any error enter image description here; and this is how i called the provider watch provider . what is wrong with my function please. Thanks for the reading.