addPathToMap function

Map<String, dynamic> addPathToMap(
  1. Map<String, dynamic> map,
  2. List<String> keyPath,
  3. dynamic value
)

adds a dynamic value to Map<String, dynamic> yaml with the depth definded by List<String> keyPath

Implementation

Map<String, dynamic> addPathToMap(
        Map<String, dynamic> map, List<String> keyPath, dynamic value) =>
    keyPath.length == 1
        ? Map<String, dynamic>.from({...map, keyPath.first: value})
        : Map<String, dynamic>.from({
            ...map,
            keyPath.first:
                addPathToMap(map[keyPath.removeAt(0)] ?? {}, keyPath, value)
          });