flatMapKeys function

List<String> flatMapKeys(
  1. Map<String, Object?> map
)

takes a Map and return the flat keys to the map Example map :

{
"xyx":'some value'
"a":{
    "b":{
        "c":{
            "d":{
                "e":"end"
                }
          }
      }
   }
}

will return

[
'xyz',
'a',
'a.b',
'a.b.c',
'a.b.c.d',
'a.b.c.d.e',
]

Implementation

List<String> flatMapKeys(Map<String, Object?> map) {
  /// full flat list
  final flatKeys = <String>[];

  for (final key in map.keys) {
    final value = map[key];
    flatKeys.add(key);

    if (value is Map) {
      final children = flatMapKeys(value as Map<String, Object?>);
      flatKeys.addAll(children.map((e) => '$key.$e'));
    }
  }

  return flatKeys;
}