build method

  1. @override
UserModel? build()

Implementation

@override
UserModel? build() {
  ref.listen(
    authControllerProvider,
    (previous, next) {
      if (next.hasValue) {
        // If the user is signed out, unsubscribe from notification topics.
        if (next.asData!.value.uid == null) {
          // We pass the signed out user to unsubscribe
          ref.read(cloudMessagingServiceProvider).onSignOutHandler(
                previous?.asData?.value,
              );
        } else {
          // If the user is signed in, subscribe to notification topics.
          final notificationPreferences = {
            for (final topic in notificationOptions.keys)
              topic: ref.read(notificationPreferenceProvider(topic)),
          };
          ref.read(cloudMessagingServiceProvider).onSignInHandler(
                next.asData!.value,
                notificationPreferences,
              );
        }
        state = next.asData!.value;
      }
    },
  );
  return null;
}