AVAILABLE: 5
Hi everyone, I’m trying to create a filter for a data list in Flutter. I’m using the model generator at quicktype.io, and I’m also applying the MVC pattern.
productTemp.sort((a, b) => b.productPrice.compareTo(a.productPrice));
productTemp = productTemp.where((x) =>
x.productName.toLowerCase().contains(inputText.toLowerCase()));
productTemp = productTemp.toSet().toList();
Is there any incorrect implementation causing the following error?
[ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: type 'WhereIterable' is not a subtype of type 'List'
Solution
Use where
to accomplish this task.
Your productTemp
is a List
, but the where
method returns an Iterable
. You need to convert the output of where
to a List
.
productTemp.where(
(x) => x.productName.toLowerCase().contains(inputText.toLowerCase())
).toList();