stateEvents property
The runtime state changes of this probe.
This is useful for listening on state changes as specified in ProbeState
.
Can e.g. be used in a StreamBuilder when showing the UI of a probe.
The following example is taken from the CARP Mobile Sensing App
Widget buildProbeListTile(BuildContext context, ProbeModel probe) {
return StreamBuilder<ProbeStateType>(
stream: probe.stateEvents,
initialData: ProbeState.created,
builder: (context, AsyncSnapshot<ProbeState> snapshot) {
if (snapshot.hasData) {
return ListTile(
isThreeLine: true,
leading: Icon(
probe.icon.icon,
size: 50,
color: probe.icon.color,
),
title: Text(probe.name),
subtitle: Text(probe.description),
trailing: probe.stateIcon,
);
} else if (snapshot.hasError) {
return Text('Error in probe state - ${snapshot.error}');
}
return Text('Unknown');
},
);
}
This will update the trailing icon of the probe every time the probe change
state (e.g. from resumed
to paused
).
Implementation
Stream<ProbeState> get stateEvents => _stateEventController.stream;