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
Thediff property provides convenient access to what changed:
Integrating with BLoC
Fire events to your business logic layer using pattern matching: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: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:Transition observers vs Surface observers
When to use Transition Observers
When to use Transition 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
When to use Surface Observers
When to use Surface Observers
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
Important notes
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