我正在尝试根据其类别过滤食品,但不断收到以下错误。这个想法是使用 Provider 包手动传递我选择的类别的字符串,然后从包含食品的列表中过滤和打印与类别匹配的项目。
I/flutter ( 7404): ??? EXCEPTION CAUGHT BY WIDGETS LIBRARY ????????????????????????????????????????????????????????????
I/flutter ( 7404): The following _TypeError was thrown building TestClass(dirty, dependencies:
I/flutter ( 7404): [_InheritedProviderScope<DummyData>]):
I/flutter ( 7404): type 'WhereIterable<Products>' is not a subtype of type 'List<Products>'
Run Code Online (Sandbox Code Playgroud)
这是虚拟数据的片段,其中我分别在名为类别和产品的列表中定义了类别和食品。我非常有信心最后的过滤器没有很好地定义。
class DummyData with ChangeNotifier {
List<Categories> categories = [
Categories(
catId: '1',
title: 'American',
imageUrl: 'https://www.recipetineats.com/wp-content/uploads/2016/02/Beef-Hamburgers_7-2.jpg?w=500&h=500&crop=1'
),
Categories(
catId: '2',
title: 'North Indian',
imageUrl: 'https://static.toiimg.com/thumb/53205522.cms?width=1200&height=1200'
),
Categories(
catId: '3',
title: 'Chinese',
imageUrl: 'https://uploads-ssl.webflow.com/5c481361c604e53624138c2f/5c6cd55ca1bcb14248ded5c4_chilli-pork-website-thumbnail-.png'
),
];
List<Products> products = [ …Run Code Online (Sandbox Code Playgroud) 我们的想法是创建一个高级搜索页面,使用户能够根据自己的选择过滤数据,选择多达五个选项来缩小搜索范围。结果随后将显示在表格上。话虽如此,用户可以决定通过仅使用单个选项(即“按州”)或通过采用多个选项(即“按名称”、“按地区”和“按类别”)或如前所述的最多 5 个选项来进行过滤。但是,我无法弄清楚如何做到这一点。您会发现屏幕截图后跟以下代码:
用户选择使用“按州”选项进行过滤的场景
场景,选择多个选项以缩小搜索范围
代码如下:
const AdvanceFilterScreen = () => {
const [byNameFilter, setByNameFilter] = useState(false);
const [name, setName] = useState('');
const [byDateFilter, setByDateFilter] = useState(false);
const [byCategoryFilter, setByCategoryFilter] = useState(false);
const [category, setCategory] = useState('');
const [byDistrictFilter, setByDistrictFilter] = useState(false);
const [district, setDistrict] = useState('');
const [byStateFilter, setByStateFilter] = useState(false);
const [status, setStatus] = useState('');
const [bySerialNumberFilter, setBySerialNumberFilter] = useState(false);
const [serialNumber, setSerialNumber] = useState('');
const [byIssueFilter, setbyIssueFilter] = useState(false);
const [buttonValue, setFilterButtonValue] = useState('');
//What the following …Run Code Online (Sandbox Code Playgroud)