getActiveResourcesOfType method
returns all resources of a specific type
Implementation
Future<List<Resource>> getActiveResourcesOfType({
List<Dstu2ResourceType>? resourceTypes,
List<String>? resourceTypeStrings,
Resource? resource,
String? pw,
}) async {
final Set<Dstu2ResourceType> typeList = <Dstu2ResourceType>{};
if (resource?.resourceType != null) {
typeList.add(resource!.resourceType!);
}
if (resourceTypes != null && resourceTypes.isNotEmpty) {
typeList.addAll(resourceTypes);
}
if (resourceTypeStrings != null) {
for (final String type in resourceTypeStrings) {
final Dstu2ResourceType? resourceType = resourceTypeFromStringMap[type];
if (resourceType != null) {
typeList.add(resourceType);
}
}
}
final List<Resource> resourceList = <Resource>[];
await _ensureInit(pw: pw);
for (final Dstu2ResourceType resourceType in typeList) {
final Box<Map<dynamic, dynamic>> box =
await _getBox(resourceType: resourceType, pw: pw);
final List<Map<String, dynamic>> newResources = box.values
.map((Map<dynamic, dynamic> e) =>
jsonDecode(jsonEncode(e)) as Map<String, dynamic>)
.toList();
resourceList.addAll(
newResources.map((Map<String, dynamic> e) => Resource.fromJson(e)));
}
return resourceList;
}