title: Using Fold Method In Flutter Web Doesnt Work
body: <p>I have a fold method and sort that works in Flutter for mobile but, doesnt work in the web version. When I call on my home page, this is the error I get:</p>
  
  <blockquote>
    <p>FutureBuilder 
        lib/…/HomePage/Home.dart:356
        When the exception was thrown, this was the stack
        packages/BuddiesWebApp/Pages/HomePage/Home.dart.lib.js 3503:35  [_getProductsInHeadings]
        packages/BuddiesWebApp/Pages/HomePage/Home.dart.lib.js 3640:70  
        packages/flutter/src/widgets/async.dart.lib.js 517:77                                         build</p>
  </blockquote>
  
  <p>This is my Filter method:</p>
  
  <pre><code>  List&lt;ProductsInHeading&gt; _getProductsInHeadings(List&lt;Product&gt; items) {
      switch (selectedTab) {
        case FilterTabs.Feels:
          final Map&lt;String, List&lt;Product&gt;&gt; allFeelings =
              Map.fromEntries(TabCategories.feeling.map((e) =&gt; MapEntry(e, [])));
  
          Map&lt;String, List&lt;Product&gt;&gt; headingItems =
              items.fold(allFeelings, (feelings, element) {
            if (!feelings.containsKey(element.effect)) {
              return feelings;
            }
  
            return feelings
              ..update(element.effect, (value) =&gt; value..add(element));
          });
          productList = headingItems;
          print("headingItems: $headingItems");
  
          return headingItems.entries
              .map((e) =&gt; ProductsInHeading(e.key, e.value..sort()))
              .toList()
                ..sort()
                ..where((e) =&gt; e.products.length != 0);
          break;
  
  
  
    case FilterTabs.Rec:
      final Map&lt;String, List&lt;Product&gt;&gt; allRecommended =
          Map.fromEntries(recCategories.map((e) =&gt; MapEntry(e, [])));
  
      Map&lt;String, List&gt; headingItems =
          items.fold(allRecommended, (feeling, element) {
        if (!feeling.containsKey(element.effect)) {
          return feeling;
        }
  
        return feeling
          ..update(recCategories.toString(), (value) =&gt; value..add(element));
      });
      productList = headingItems;
      print("headingItems: $headingItems");
  
      return headingItems.entries
          .map((e) =&gt; ProductsInHeading(e.key, e.value..sort()))
          .toList()
            ..sort()
            ..where((e) =&gt; e.products.length != 0);
      break;
  
  
  
        case FilterTabs.Relief:
          // usage might be wrong, I'm not sure
          final Map&lt;String, List&lt;Product&gt;&gt; allRecovery =
              Map.fromEntries(TabCategories.usage.map((e) =&gt; MapEntry(e, [])));
  
          Map&lt;String, List&lt;Product&gt;&gt; headingItems =
              items.fold(allRecovery, (recovery, element) {
            if (!recovery.containsKey(element.usage)) {
              return recovery;
            }
  
            return recovery
              ..update(element.usage, (value) =&gt; value..add(element));
          });
          productList = headingItems;
  
          // print("headingItems: $headingItems");
          return headingItems.entries
              .map((e) =&gt; ProductsInHeading(e.key, e.value..sort()))
              .toList()
                ..sort();
          break;
        case FilterTabs.Categories:
          // usage might be wrong, I'm not sure
          final Map&lt;String, List&lt;Product&gt;&gt; allCategories = Map.fromEntries(
              TabCategories.prodCategory.map((e) =&gt; MapEntry(e, [])));
  
          Map&lt;String, List&lt;Product&gt;&gt; headingItems =
              items.fold(allCategories, (categories, element) {
            if (!categories.containsKey(element.productCategory)) {
              return categories;
            }
  
            return categories
              ..update(element.productCategory, (value) =&gt; value..add(element));
          });
  
          // print("headingItems: $headingItems");
          productList = headingItems;
  
          return headingItems.entries
              .map((e) =&gt; ProductsInHeading(e.key, e.value..sort()))
              .toList()
                ..sort()
                ..where((e) =&gt; e.products.length != 0);
          break;
  
        case FilterTabs.All:
          return TabCategories.all
              .map((e) =&gt; ProductsInHeading(e, items))
              .toList();
      }
      throw UnsupportedError("Unsupported tab type");
    }
  </code></pre>
  
  <p>I'm not sure how to migrate this properly. Please help</p>