我在flutter中使用grid view.count()创建了一个网格视图。
例如,在开始时,我的网格视图中有8个项目(最大值为8)。我想根据用户稍后选择的条件从网格中删除特定单元格。
我很难做到这一点,就好像我用一个空容器替换了网格单元(动态的条件检查)它仍然发生在网格中,而我希望该单元被完全删除(甚至不发生在网格视图中)。
有办法做到这一点吗?
编辑
这是密码。条件检查在第10行的返回语句中。
Expanded(
child: GridView.count(
physics: BouncingScrollPhysics(),
scrollDirection: Axis.vertical,
crossAxisCount: 2,
childAspectRatio: 0.7,
children: new List<Widget>.generate(
category != null ? category.category.length : 0,
(index) {
return _lowerLimit < category.category.elementAt(index).price && _upperLimit > caregory.categoty.elementAt(index).price ?
GridTile(
child: Column(
children: <Widget>[
Container(
margin: EdgeInsets.all(3.0),
padding:
EdgeInsets.symmetric(vertical: 30.0),
color: Colors.white,
child: Hero(
tag: category.category
.elementAt(index)
.productId,
child: Material(
child: InkWell(
onTap: () {
Navigator.of(context).push(
CupertinoPageRoute(
builder: (context) =>
ItemDetails(
category.category
.elementAt(index)
.productId,
category.category
.elementAt(index)
.name,
category.category
.elementAt(index)
.description,
category.category
.elementAt(index)
.image,
)));
},
child: Stack(
children: <Widget>[
Center(
child: Image(
image: _loadImage(index),
height: 162.0,
width: 200.0,
),
)
],
),
),
),
),
),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
margin: EdgeInsets.only(left: 15.0),
child: Column(
//mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment:
CrossAxisAlignment.start,
children: <Widget>[
Container(
width: 120.0,
child: Hero(
tag: category.category
.elementAt(index)
.name,
child: Text(
category.category
.elementAt(index)
.name,
style: TextStyle(
fontSize: 12.5,
fontWeight:
FontWeight.bold),
overflow:
TextOverflow.ellipsis,
),
),
margin:
EdgeInsets.only(right: 5.0),
),
Container(
height: 2.0,
),
Text(
AppConstants.CURRENCY_SYMBOL +
" " +
double
.tryParse(category
.category
.elementAt(index)
.price)
.toStringAsFixed(2),
style: TextStyle(
fontSize: 14.0,
fontWeight: FontWeight.bold,
color: Colors.blue),
overflow: TextOverflow.clip,
)
],
),
),
Container(
margin: EdgeInsets.only(right: 10.0),
alignment: Alignment.topRight,
child: Icon(
Icons.favorite,
color: Colors.blue,
),
)
],
),
Divider(
color: Colors.blue,
indent: 10.0,
),
],
),
) : Container();
}),
),
)