State Management API

Provider-based reactive state with an optional BLoC alternative.

EventProvider

lib/state/providers/event_provider.dart

The primary state holder for events. Extends ChangeNotifier and provides an O(1) indexed event list.

Key Design Decisions

Properties

PropertyTypeDescription
eventsUnmodifiableListView<EventModel>Read-only view of all events
eventCountintNumber of events
isEmptyboolWhether event list is empty

Methods

MethodSignatureDescription
setEvents(List<EventModel>) β†’ voidReplace entire list + rebuild index. Used during initial load.
addEvent(EventModel) β†’ voidAppend event, update index incrementally.
removeEvent(String id) β†’ voidRemove by ID using O(1) index lookup. Rebuilds index after removal (indices shift).
updateEvent(EventModel) β†’ voidReplace event at its indexed position. O(1).
getEventById(String id) β†’ EventModel?O(1) lookup via index map.
clearEvents() β†’ voidRemove all events and clear index.

Usage

// In a widget final provider = context.watch<EventProvider>(); // Read events (reactive β€” triggers rebuild on change) for (final event in provider.events) { print(event.title); } // Look up specific event final event = provider.getEventById('uuid-123'); // Mutate (triggers notifyListeners β†’ widget rebuild) context.read<EventProvider>().addEvent(newEvent);

UserProvider

lib/state/providers/user_provider.dart

Manages the current user session. Set by AuthGate on successful authentication.

Properties & Methods

MemberTypeDescription
currentUserUserModel?Currently authenticated user (null if logged out)
setUser(user)voidSet the current user and notify listeners
clearUser()voidClear user session

EventBloc

lib/state/blocs/event_bloc.dart

Alternative state management using the BLoC pattern via Cubit. Provides a state machine approach that can coexist with the Provider-based approach.

States

StateDescription
EventInitialBefore any events have been loaded
EventLoadedContains the current list of events
EventErrorError state with message (reserved for future use)

Methods

MethodDescription
loadEvents(List<EventModel>)Transition to EventLoaded with the given events
addEvent(EventModel)Append event (only in EventLoaded state, no-op otherwise)
removeEvent(String id)Remove event by ID (only in EventLoaded state)

State Transitions

EventInitial ─── loadEvents() ──→ EventLoaded
                                     ↕ addEvent() / removeEvent()
                                  EventLoaded (new list)
      

When to Use Which?

βœ… Use EventProvider when…

  • You need O(1) ID-based lookups
  • You're in a standard widget tree
  • You want simple reactive updates
  • You're pairing with EventService for persistence

βœ… Use EventBloc when…

  • You prefer explicit state transitions
  • You want to use BlocBuilder/BlocListener
  • You need testable state machines
  • You're integrating with complex async flows