notificationPreferenceProvider top-level property

StateProviderFamily<bool, String> notificationPreferenceProvider
final

A provider that reads the notification preferences from the shared preferences for a specific topic. If set, it will also update the notification preferences in the shared preferences and in Firebase Cloud Messaging.

Implementation

final notificationPreferenceProvider =
    StateProvider.family<bool, String>((ref, topic) {
  final prefs = ref.watch(sharedPreferencesProvider);
  final currentValue = prefs.getBool(topic) ?? true;
  ref.listenSelf(
    (previous, next) {
      if (kIsWeb) return;
      ref
          .read(cloudMessagingServiceProvider)
          .updateTopicSubscription(topic, enabled: next);
      prefs.setBool(topic, next);
    },
  );
  return currentValue;
});