changeLocale method

Future<void> changeLocale(
  1. Locale locale
)

Change the locale and persist it to SharedPreferences.

Implementation

Future<void> changeLocale(Locale locale) async {
  emit(locale);
  final prefs = await SharedPreferences.getInstance();
  final saved = locale.countryCode != null && locale.countryCode!.isNotEmpty
      ? '${locale.languageCode}_${locale.countryCode}'
      : locale.languageCode;
  await prefs.setString(_kSavedLocaleKey, saved);
}