readYamlFile static method
Read JSon file as Map specifically for provided group and subgroup
Implementation
static Future<Map<String, dynamic>> readYamlFile(String yamlFile,
{String? group, String? subGroup}) async {
try {
String fileAsString = await TGFileUtil.readFile(yamlFile);
final Map? map = loadYaml(fileAsString);
if (group == null || group.isEmpty) {
return map as FutureOr<Map<String, dynamic>>;
}
// Group entries
Map<String, dynamic> groupMap = <String, dynamic>{};
for (MapEntry<String, dynamic> entry in map![group].entries) {
groupMap[entry.key] = entry.value;
}
if (subGroup == null || subGroup.isEmpty) return groupMap;
// Sub Group entries
Map<String, dynamic> subGroupMap = <String, dynamic>{};
for (MapEntry<String, dynamic> entry in groupMap[subGroup].entries) {
subGroupMap[entry.key] = entry.value;
}
return subGroupMap;
} catch (e) {
TGLog.e("Unable to load " + group! + " from file " + yamlFile);
TGLog.e(e.toString());
}
return <String, dynamic>{};
}