У меня есть метод сворачивания и сортировки, который работает во Flutter для мобильных устройств, но не работает в веб-версии. Когда я захожу на свою домашнюю страницу, я получаю следующее сообщение об ошибке:
FutureBuilder lib /… / HomePage / Home.dart: 356 Когда было выброшено исключение, это был стек пакетов / BuddiesWebApp / Pages / HomePage / Home.dart.lib. js 3503: 35 [_getProductsInHeadings] пакетов / BuddiesWebApp / Pages / HomePage / Home.dart.lib. js 3640: 70 пакетов / flutter / src / widgets / asyn c .dart.lib. js 517: 77 build
Это мой метод фильтрации:
List<ProductsInHeading> _getProductsInHeadings(List<Product> items) {
switch (selectedTab) {
case FilterTabs.Feels:
final Map<String, List<Product>> allFeelings =
Map.fromEntries(TabCategories.feeling.map((e) => MapEntry(e, [])));
Map<String, List<Product>> headingItems =
items.fold(allFeelings, (feelings, element) {
if (!feelings.containsKey(element.effect)) {
return feelings;
}
return feelings
..update(element.effect, (value) => value..add(element));
});
productList = headingItems;
print("headingItems: $headingItems");
return headingItems.entries
.map((e) => ProductsInHeading(e.key, e.value..sort()))
.toList()
..sort()
..where((e) => e.products.length != 0);
break;
case FilterTabs.Rec:
final Map<String, List<Product>> allRecommended =
Map.fromEntries(recCategories.map((e) => MapEntry(e, [])));
Map<String, List> headingItems =
items.fold(allRecommended, (feeling, element) {
if (!feeling.containsKey(element.effect)) {
return feeling;
}
return feeling
..update(recCategories.toString(), (value) => value..add(element));
});
productList = headingItems;
print("headingItems: $headingItems");
return headingItems.entries
.map((e) => ProductsInHeading(e.key, e.value..sort()))
.toList()
..sort()
..where((e) => e.products.length != 0);
break;
case FilterTabs.Relief:
// usage might be wrong, I'm not sure
final Map<String, List<Product>> allRecovery =
Map.fromEntries(TabCategories.usage.map((e) => MapEntry(e, [])));
Map<String, List<Product>> headingItems =
items.fold(allRecovery, (recovery, element) {
if (!recovery.containsKey(element.usage)) {
return recovery;
}
return recovery
..update(element.usage, (value) => value..add(element));
});
productList = headingItems;
// print("headingItems: $headingItems");
return headingItems.entries
.map((e) => ProductsInHeading(e.key, e.value..sort()))
.toList()
..sort();
break;
case FilterTabs.Categories:
// usage might be wrong, I'm not sure
final Map<String, List<Product>> allCategories = Map.fromEntries(
TabCategories.prodCategory.map((e) => MapEntry(e, [])));
Map<String, List<Product>> headingItems =
items.fold(allCategories, (categories, element) {
if (!categories.containsKey(element.productCategory)) {
return categories;
}
return categories
..update(element.productCategory, (value) => value..add(element));
});
// print("headingItems: $headingItems");
productList = headingItems;
return headingItems.entries
.map((e) => ProductsInHeading(e.key, e.value..sort()))
.toList()
..sort()
..where((e) => e.products.length != 0);
break;
case FilterTabs.All:
return TabCategories.all
.map((e) => ProductsInHeading(e, items))
.toList();
}
throw UnsupportedError("Unsupported tab type");
}
Я не уверен, как правильно его перенести. Пожалуйста, помогите