localPreferenceProvider top-level property

StateProvider localPreferenceProvider
final

Implementation

final localPreferenceProvider = StateProvider<AppLocale?>((ref) {
  final prefs = ref.watch(sharedPreferencesProvider);
  final currentValue = prefs.getString('locale');
  ref.listenSelf(
    (previous, next) {
      next == null
          ? prefs.remove('locale')
          : prefs.setString('locale', next == AppLocale.nl ? 'nl' : 'en');
    },
  );
  return currentValue == null
      ? null
      : currentValue == 'nl'
          ? AppLocale.nl
          : AppLocale.en;
});