asTreeOfKeyString function

dynamic asTreeOfKeyString(
  1. Object? tree
)

Maps tree:

  • If tree is a Map to a Map<String,dynamic.
  • If tree is a List to a List<Map<String,dynamic>.

Implementation

dynamic asTreeOfKeyString(Object? tree) {
  if (tree == null) return null;

  if (tree is Map) {
    return Map<String, dynamic>.fromEntries(tree.entries.map((e) {
      return MapEntry<String, dynamic>('${e.key}', asTreeOfKeyString(e.value));
    }));
  } else if (tree is List) {
    return tree.map(asTreeOfKeyString).toList();
  } else {
    return tree;
  }
}