listen method
void
listen(
- String id
)
override
Implementation
@override
void listen(String id) {
_eventStream[id] = eventChannel.receiveBroadcastStream().map((event) {
if (event['id'] == id) {
final eventName = event['event'] as String;
switch (eventName) {
case 'state':
{
final state = event['value'] as int;
return StateEvent(value: state.toDouble());
}
case 'error':
{
return ErrorEvent(value: event['value'] as String);
}
case 'duration':
{
return DurationEvent(value: event['value'] as double);
}
case 'samples':
{
final samples = (event['value'] as List<dynamic>)
.map((e) => e as double)
.toList();
return SamplesEvent(value: samples);
}
case 'completed':
{
return CompletedEvent(value: event['value'] as bool);
}
default:
{
return NoneEvent();
}
}
}
});
}