listen method
Stream<Resource?>
listen(
{ - required Dstu2ResourceType resourceType,
- String? id,
- String? pw,
})
Implementation
Stream<Resource?> listen({
required Dstu2ResourceType resourceType,
String? id,
String? pw,
}) async* {
await _ensureInit(pw: pw);
final Box<Map<dynamic, dynamic>> box =
await _getBox(resourceType: resourceType, pw: pw);
if (id == null) {
yield* box.watch().map((BoxEvent event) {
if (!event.deleted) {
return Resource.fromJson(
jsonDecode(jsonEncode(event.value)) as Map<String, dynamic>);
} else {
return null;
}
});
} else {
yield* box.watch(key: id).map((BoxEvent event) {
if (!event.deleted) {
return Resource.fromJson(
jsonDecode(jsonEncode(event.value)) as Map<String, dynamic>);
} else {
return null;
}
});
}
}