title: How to show in a ListView a Tree of Strings?
body: <p>I have a <code>Map&lt;String, dynamic&gt;</code>, where dynamic is a dynamic tree of <code>Strings</code>. I need to show in a <code>ListView</code> (or another Widget that allow to show a Tree structure) the Strings and their children. Each String is a collapsable item (if has children) of the ListView. For example:</p>
  
  <pre><code>Text
       text 
             text
             text
       text 
  text
       text
  text
  text
  </code></pre>
  
  <p>this is the code of an example of the tree:</p>
  
  <pre><code>void main() {
    Map&lt;String, dynamic&gt; joinTrees(int level, int maxLevel,
        List&lt;List&lt;String&gt;&gt; trees, Map&lt;String, dynamic&gt; tmpMap) {
      if (maxLevel &lt; 0) return {};
      List&lt;String&gt; nodes = trees.map((tree) =&gt; tree[level]).toSet().toList();
      print(nodes);
  
      for (String node in nodes) {
        List&lt;List&lt;String&gt;&gt; childrenBranchs =
            trees.where((tree) =&gt; tree[level] == node).toList();
        if (childrenBranchs.length == 1 &amp;&amp;
            childrenBranchs[0][childrenBranchs[0].length - 1] == node) {
          print("leaf: " + node);
          tmpMap[node] = null;
        } else {
          Map&lt;String, dynamic&gt; childrenTree = joinTrees(
              level + 1, maxLevel, childrenBranchs, new Map&lt;String, dynamic&gt;());
          print("node: " + node);
          tmpMap[node] = childrenTree;
        }
      }
      return tmpMap;
    }
  
    List&lt;List&lt;String&gt;&gt; trees = [
      ["A", "A11", "A21"],
      ["A", "A12"],
      ["A", "A11", "A22"],
      ["B", "B11", "B21"],
      ["C"]
    ];
    int maxLength = trees
        .map((tree) =&gt; tree.length)
        .toList()
        .reduce((curr, next) =&gt; curr &gt; next ? curr : next);
    int maxLevel = maxLength - 1;
  
    print(trees);
    print(maxLength);
    Map&lt;String, dynamic&gt; joinedTree =
        joinTrees(0, maxLevel, trees, new Map&lt;String, dynamic&gt;());
    print(joinedTree);
  }
  </code></pre>
  
  <p>this is de ouput of joinedTree:</p>
  
  <pre><code>{
   A: 
      {
       A11: 
            {
             A21: null, 
             A22: null
            }, 
       A12: null
      }, 
   B: 
      {
       B11: 
           {
             B21: null
           }
      }, 
   C: null
  
  }
  </code></pre>