Skip to main content

Overview

Guards are where your presentation business logic lives. This guide shows you how to build guards from simple to production-level complexity.

Basic guard

Start with a simple guard that sets the highest priority item as active:
class SimpleCampaignGuard extends PresentumGuard<CampaignItem, AppSurface, CampaignVariant> {
  @override
  FutureOr<PresentumState> call(
    PresentumStorage storage,
    List<PresentumHistoryEntry> history,
    PresentumState$Mutable state,
    List<CampaignItem> candidates,
    Map<String, Object?> context,
  ) async {
    for (final candidate in candidates) {
      state.setActive(candidate.surface, candidate);
    }
    return state;
  }
}

Production guard examples

See real implementations:

See all production guards

Complete guard implementations from a live app