Skip to main content

Overview

Transition observers let you react to state changes in the Presentum engine. Unlike event handlers (which respond to user actions like shown/dismissed/converted), transition observers respond to internal state changes. Each transition includes a comprehensive diff showing exactly what changed between states.
Use transition observers for: - Integrating with BLoC, Provider, Cubit - Conditional data fetching based on active items - Custom analytics for state flow - Debug logging of state changes

Basic observer

Transition structure

Every transition includes:
PresentumState$Immutable
required
State before the transition
PresentumState$Immutable
required
State after the transition
DateTime
required
When the transition occurred
PresentumStateDiff
Lazily computed diff between old and new states

Diff information

The diff property provides convenient access to what changed:
For detailed change information including which surface each change occurred on, use pattern matching:

Integrating with BLoC

Fire events to your business logic layer using pattern matching:
Or handle only specific change types with maybeMap:

Register observers

Add transition observers when creating Presentum:

Conditional data fetching

Fetch additional data when specific presentations become active:

Production example: Maintenance mode observer

This real-world observer from the example app manages app update checks based on maintenance mode:
Register it when creating the Presentum instance:
See full source →
This observer implements complex business logic (progressive timer backoff, update status management) without any widget overhead. It’s pure side effects
  • exactly what transition observers are designed for.

Debug logging

Track state flow in development with pattern matching:
Simpler version using convenience getters:

Transition observers vs Surface observers

Use transition observers for side effects and business logic: - Analytics tracking - API calls or data fetching - BLoC/Provider/Cubit integration - Logging and monitoring - Starting/stopping timers - Any logic that doesn’t render UI Key indicator: No widget rendering, pure logic
Use surface observers for UI rendering: - Showing/hiding snackbars or banners - Triggering widget animations - Rendering overlays or floating UI - Any visual element that responds to state Key indicator: Your code renders or manages widgets
If your observer would be a widget with build() returning just widget.child, use a transition observer instead. You’re adding unnecessary widget overhead for non-UI concerns.

Important notes

Do NOT call setState or transaction inside transition observers.This creates circular dependencies and infinite loops. Instead, dispatch events to your business logic layer (BLoC, Provider) which can then coordinate state changes through the public API.
Transition observers run after guards approve but before listeners are notified. They’re synchronous in the state change flow.If an observer throws, the state transition continues. Other observers still run.

Next steps

Event system

Handle user interaction events

Guards

Control what gets shown

State structure

Understand state and diffs