title: Flutter Remove Multiple List Items In For Loop (Multiple Returns In A For Loop)
body: <p>I have a list of food items. That has a category, subCategory1, subCategory2 ect.</p>
  
  <p>When the user unselects an category item. They are also unselecting the subCategory1, subCatategory2 items etc as they are children of the original categogory item like this:</p>
  
  <p><a href="https://i.stack.imgur.com/pCrF3.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pCrF3.gif" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/KKTps.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KKTps.jpg" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/8N1NG.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8N1NG.jpg" alt="enter image description here"></a></p>
  
  <p>So I have a for loop that is running through looking for children category list elements and removing them like this:</p>
  
  <pre><code>  // Remove a category item and all of its children
    if (categoryType == "category") {
      List&lt;String&gt; subCategory1Children = List&lt;String&gt;.from(
          snapshot.data.documents[gridIndex]['subCategory1Children']);
  
      // Remove the subcategory items
      for (int i = 0; i &lt; foodDrinkMenuElements['subCategory1'].length; i++) {
        String subID = foodDrinkMenuElements['subCategory1'][i];
        int removalIndex = _indexOfListGridElement('subCategory1', subID);
  
        if (subCategory1Children.contains(subID)) {
          _removeCategoryGridItem(removalIndex, subID, 'subCategory1');
        }
      }
  
      //Remove the actual item being pressed
      _removeCategoryGridItem(listIndex + 1, id, categoryType);
    }
  </code></pre>
  
  <p>Which calls _removeCategoryGridItem() like this:</p>
  
  <pre><code>void _removeCategoryGridItem(int removalIndex, String id, String categoryType) {
    _FoodandDrinkKey.currentState.removeItem(removalIndex,
        (BuildContext context, Animation&lt;double&gt; animation) {
      return _buildListItem(removalIndex, animation);
    });
    foodDrinkMenuElements[categoryType].remove(id);
  }
  </code></pre>
  
  <p>The For loop is always finishing after 1 list item is removed. I assume this is because of the return statement in the function _removeCategoryGridItem.</p>
  
  <p>I have seen other answers that say to put it in an list and run through the list but I don't see how that applies here.</p>
  
  <p>Thanks for your help</p>