An app widget should not reconstruct the application's complete repository graph whenever the launcher asks it to render.
Publish a compact snapshot:
@Serializable
data class EnergyWidgetSnapshot(
val score: Int?,
val label: String?,
val updatedAtEpochMillis: Long,
)
The app maps domain state into this display contract after meaningful changes, stores it in widget-accessible storage, and requests an update. Glance reads the snapshot and renders quickly.
Version the stored representation or provide tolerant defaults. An application upgrade can leave an older snapshot behind.
Widgets need designed missing and stale states. Showing zero for absent health data is misleading. Show an unknown state and a useful action to open or refresh the app.
Interactive actions should perform bounded work and then republish authoritative state. Do not mutate only the widget display.
Keep widget dimensions and launcher constraints in mind; Glance resembles Compose but does not support every Compose API.
Test the mapper independently, then test snapshot decoding and representative widget states. A published snapshot is a stable boundary between two lifecycles inside one application.