【发布时间】:2019-09-04 16:06:05
【问题描述】:
我在 Flutter 中有一个 ListView 构建器。我将其用作搜索功能。如果列表中的项目包含输入字段中的字母,它会使用特定索引构建项目。一切正常。 问题是我希望用户可以找到具有多个关键字的项目。因此,我认为添加更多条件会很好。如果第一个关键字列表搜索不正确,请在下一个列表中查找关键字是否存在。不同列表中的索引引用同一个对象。我怎样才能添加这个条件。我用复制和过去尝试过,但在第一个条件之后,AS 只是监督第二个条件。
Widget build(BuildContext context) {
return new Material(
child: new Column(children: <Widget>[
new Padding(
padding: new EdgeInsets.only(top: 20.0),
),
new Expanded(
child: new ListView.builder(
itemCount: shops.length,
itemBuilder: (BuildContext context, int index) {
return filter == null || filter == ""
? new Card(
child: ListTile(
leading: ConstrainedBox(
constraints: BoxConstraints(
minWidth: 115,
minHeight: 44,
maxWidth: 115,
maxHeight: 64,
),
child: Image.asset(images[index], fit: BoxFit.cover),
),
title: Text(shops[index]),
subtitle: Text(streets[index]),
trailing: Icon(Icons.more_vert),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => BarberHome()),
);
},
))
: shops[index].toLowerCase().contains(filter.toLowerCase()) ? //the first condition
new Card(
child: ListTile(
leading: ConstrainedBox(
constraints: BoxConstraints(
minWidth: 115,
minHeight: 44,
maxWidth: 115,
maxHeight: 64,
),
child:
Image.asset(images[index], fit: BoxFit.cover),
),
title: Text(shops[index]),
subtitle: Text(streets[index]),
trailing: Icon(Icons.more_vert),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => BarberHome()),
);
},
))
// here i tried to insert the second condition like that
//: streets[index].toLowerCase().contains(filter.toLowerCase()) ?
// ....
: new Container();
}))
]));
} }
【问题讨论】: