findInMap function
goes into the map extract the value by the key
Implementation
Object? findInMap(
String path,
Map map, {
String splitOperator = '.',
}) {
/// extract if no parent
if (!path.contains('.')) return map[path];
/// split and remove empty
final keys = path.split('.')..removeWhere((e) => e.isEmpty);
/// if the key is nested
if (keys.isNotEmpty) {
if (keys.length == 1) return map[keys.first];
final firstKey = keys.first;
final value = map[firstKey];
if (value is Map) {
final newKey = path.replaceFirst('$firstKey.', '');
return findInMap(
newKey,
value,
splitOperator: splitOperator,
);
}
}
}