filteredNotificationsFamily top-level property

AutoDisposeProviderFamily<AsyncValue<List<AppNotification>>, String> filteredNotificationsFamily
final

Provides a list of the user's received app notifications, filtered to only include notifications with contents that contain the provided text.

Implementation

final filteredNotificationsFamily =
    Provider.autoDispose.family<AsyncValue<List<AppNotification>>, String>(
  (ref, String filterText) {
    final notifications = ref.watch(allNotificationsProvider);

    bool containsFilterText(String? text) {
      return text != null && text.toLowerCase().contains(filterText);
    }

    return notifications.mapValue(
      (value) => value
          .where(
            (notification) =>
                filterText.isEmpty ||
                containsFilterText(notification.message) ||
                containsFilterText(notification.displayName) ||
                containsFilterText(notification.serialNumber),
          )
          .sortedByCompare(
            (notification) => notification.timestamp,
            _mostRecentDate,
          ),
    );
  },
);