Overview
The Synheart Session Dart SDK provides a stream-based API for running timed biometric sessions. Sessions emit session frames with HR metrics at configurable intervals and deliver a final summary when complete. Frames can include behavioral signal data (typing, scrolling, taps, app switches, idle gaps, stability/fragmentation indices) when aBehaviorProvider is configured. A built-in mock engine lets you develop and test without hardware.
Key Features:
- Stream-based session lifecycle (
SessionStarted->SessionFrame*->SessionSummary) - Pluggable
BiosignalProviderand optionalBehaviorProvider - Companion-watch sessions on Apple Watch and Wear OS through
WatchBiosignalProvider - Built-in mock engine with seeded output
- Configurable session modes, duration, and compute profile
The SDK computes mean HR. HRV (
hr_sdnn_ms, rmssd_ms, pnn50) is supplied by the host through ingestHsiMetrics() and is 0.0 until then. See HRV metrics.Installation
Add to yourpubspec.yaml:
Requirements
- Dart SDK
>=3.8.0 <4.0.0 - Flutter
>=3.22.0
Quick Start
Mock Mode (Development)
SessionEvent is sealed, so a switch without a default must cover all five subclasses, including BiosignalFrame().
Live Mode with a Companion Watch
SynheartSession() takes two optional named arguments: biosignalProvider and behaviorProvider. Watch routing happens only when biosignalProvider is a WatchBiosignalProvider: startSession and stopSession then also send start_session / stop_session commands to the companion app (WatchConnectivity on iOS, Wearable Data Layer on Android). The watch’s events feed the phone-side engine as HR samples, and the phone-side engine emits the frames you receive.
There is no fallback to another source. If no watch is reachable, frames still arrive on schedule with sample_count 0 and hr_mean_bpm 0.0. With no biosignalProvider at all, the same happens. See Lifecycle.
Watch Connectivity
Query watch connectivity status from your Flutter app:WatchStatus fields:
getWatchStatus() returns null in mock mode and whenever biosignalProvider is not a WatchBiosignalProvider. On iOS, reachable requires the watch to be paired, the companion app installed, and the watch app reachable. The start command is only sent when the watch is reachable at the moment startSession is called.Session Configuration
SessionConfig
ComputeProfile
Session Events
All events extend the sealedSessionEvent class and include a sessionId.
SessionStarted
Emitted immediately whenstartSession is called.
SessionFrame
Emitted at eachemitIntervalSec with computed session metrics.
Live engine
metrics keys:
The mock engine emits the same keys except
pnn50, computes synthetic hr_sdnn_ms and rmssd_ms from its generated data, and adds "mock": true.
BiosignalFrame
Emitted at eachrawEmitIntervalSec when includeRawSamples is true. In 0.3.0 only the mock engine emits BiosignalFrame; the live engine does not.
BiosignalSample fields:
SessionSummary
Emitted when the session completes (duration elapsed or stopped manually). The stream closes after it.SessionError
Part of the sealed hierarchy and of the wire format. Neither Dart engine emits it in 0.3.0; misuse is reported by throwingSessionInvalidStateError instead. See Errors.
Error codes:
HRV Metrics
The live engine does not compute HRV. Pass values from your HRV source (typically the Synheart runtime) withingestHsiMetrics; the latest map is used for every following frame and the summary:
dispose(), or when no session with that id is running.
Behavioral Signals
Pass aBehaviorProvider to SynheartSession() or SynheartSession.mock(). The engine pulls a snapshot at each frame and once more for the summary. The Dart SDK bundles MockBehaviorProvider; to use real behavioral data, implement BehaviorProvider over your behavior source (see Providers).
Mock Mode
Behavioral Fields
When present, thebehavior map on SessionFrame and SessionSummary includes:
The
behavior key is only present when a BehaviorProvider is configured, reports isAvailable, and returns a snapshot. Null optional fields are omitted from the map.Complete Example
API Reference
SynheartSession
Resources
- Repository: synheart-session-flutter
- Issues: GitHub Issues