setNested function

void setNested(
  1. Map<String, dynamic> map,
  2. List<String> path,
  3. Object? value
)

Implementation

void setNested(Map<String, dynamic> map, List<String> path, Object? value) {
  if (path.isEmpty) return;
  Map<String, dynamic> current = map;
  for (int i = 0; i < path.length - 1; i++) {
    final String key = path[i];
    final next = current.putIfAbsent(key, () => <String, dynamic>{});
    if (next is Map<String, dynamic>) current = next;
  }
  final lastKey = path.lastOrNull;
  if (lastKey != null) current[lastKey] = value;
}