setValue method

void setValue(
  1. Map<String, dynamic> destination,
  2. String key,
  3. dynamic value
)

Implementation

void setValue(Map<String, dynamic> destination, String key, dynamic value) {
  final path = key.split('.');
  if (path.length > 1) {
    var map = destination[path[0]];
    if (map == null) {
      map = <String, dynamic>{};
      destination[path[0]] = map;
    }
    for (var i = 1; i < path.length - 1; i++) {
      var nextMap = map[path[i]];
      if (nextMap == null) {
        nextMap = <String, dynamic>{};
        map[path[i]] = nextMap;
      }
      map = nextMap;
    }
    map[path.last] = value;
    return;
  }
  destination[key] = value;
}