title: How do I return the values of a nested structure with a list of maps in Flutter
body: <p>Still trying to learn maps and lists.</p>
  <p>My goal is to return a list from a nested list of maps. The function getMovements() works as expected. It renders a list of movements. Then I try to create another function getVariationsByMovement() which passes in the movement string name to attempt to return a list of variationNames. In my UI, I present a list of movements. The user selects a movements and the next page renders with a list of variations.</p>
  <p>I am stuck in the function below getVariationsByMovement.</p>
  <pre><code>class MovementDataSource extends ChangeNotifier{
  
    List&lt;Map&gt; getAll() =&gt; _movement;
  
    List&lt;String&gt; getMovements()=&gt; _movement
        .map((map) =&gt; MovementModel.fromJson(map))
        .map((item) =&gt; item.movement)
        .toList();
  
  // I'd  like this to return a list of movement.variation.variationName
  
    getVariationsByMovement(String movement) =&gt; _movement
        .map((map) =&gt; MovementModel.fromJson(map))
        .where((item) =&gt; item.movement == movement)
        .map((item) =&gt; item.**I AM STUCK HERE**)
        .expand((i) =&gt; i)
        .toList();
  
  
    List _movement = [
      {
        &quot;movement&quot;: &quot;Plank&quot;,
        &quot;alias&quot;: &quot;plank&quot;,
        &quot;variation&quot;: [
          {&quot;variationName&quot;: &quot;High Plank&quot;}, {&quot;variationName&quot;: &quot;Forearm Plank&quot;},
        ]
      },
      {
        &quot;movement&quot;: &quot;Side Plank&quot;,
        &quot;alias&quot;: &quot;side plank&quot;,
        &quot;variation&quot;: [
          {&quot;variationName&quot;: &quot;Side Plank Right&quot;}, {&quot;variationName&quot;: &quot;Side Plank Left&quot;},
        ],
      },
    ];
  }
  </code></pre>
  <p>My model</p>
  <pre><code>class MovementModel {
    String movement;
    String alias;
    List&lt;VariationModel&gt; variation;
  
    MovementModel({this.movement, this.alias, this.variation});
  
    // from firestore
    MovementModel.fromJson(Map&lt;String, dynamic&gt; json) {
      var list = json['variation'] as List;
      List&lt;VariationModel&gt; variationList = list.map((i) =&gt; VariationModel.fromJson(i)).toList();
      movement = json['movement'];
      alias = json['alias'];
      variation = variationList;
    }
  
    // to firestore
    Map&lt;String, dynamic&gt; toJson() {
    final Map&lt;String, dynamic&gt; data = new Map&lt;String, dynamic&gt;();
    data['movement'] = this.movement;
    data['alias'] = this.alias;
    //data['variation'] = VariationModel;
    return data;
    }
  }
  
  class VariationModel {
    String variationName;
    String description;
  
    VariationModel({this.variationName, this.description});
  
    // from firestore
    VariationModel.fromJson(Map&lt;String, dynamic&gt; json) {
      variationName = json['variationName'];
      description = json['description'];
    }
  
    // to firestore
    Map&lt;String, dynamic&gt; toJson() {
  
      return {
        'variationName': variationName,
        'description': description,
      };
    }
  }
  </code></pre>
  <p>UPDATE
  In this case I am trying to return the results to a list builder.</p>
  <pre><code>  @override
    Widget build(BuildContext context) {
      final _movementDataLocator = locator&lt;MovementDataSource&gt;();
      return ListView.builder(
          scrollDirection: Axis.vertical,
          shrinkWrap: true,
          itemCount: _movementDataLocator.getVariationsByMovement(movement).length,
          itemBuilder: (buildContext, index) {
            return Card(
              child: ListTile (
                title: Text(
                  _movementDataLocator.getVariationsByMovement(movement)[index].toString(),
                  style: TextStyle(fontSize: 20),
                ),
                trailing: Icon(Icons.keyboard_arrow_right),
                onTap: () async {
                  Navigator.push(context, MaterialPageRoute(
                      builder: (_) =&gt; SelectDefaultItemPage(variation: _movementDataLocator.getVariationsByMovement(movement)[index])));
                },
              ),
            );
          }
      );
    }
  }
  
  </code></pre>