【发布时间】:2021-03-07 01:04:45
【问题描述】:
我正在使用动画容器通过操纵动画容器的_height 字符来制作关闭动画。我正在使用ListView.builder 创建卡片,每个卡片的文本都是列表中的值(用户可以通过添加和删除项目来操作列表)。集成的GestureDetector 查找双击并删除列表中的一项并操纵高度。然而,问题在于,所有卡片的高度都被操纵和消散。
我们如何让动画高度操作只发生在用户双击的卡片上?
listview.builder 代码如下:
ListView.builder(
padding: EdgeInsets.fromLTRB(0, 0, 0, 100),
shrinkWrap: true,
scrollDirection: Axis.vertical,
itemCount: items.length,
itemBuilder: (context, index) {
return AnimatedContainer(
duration: Duration(seconds: 2),
alignment: Alignment.center,
decoration: new BoxDecoration(
color: Color(0xFF324467),
shape: BoxShape.rectangle,
borderRadius: BorderRadius.all(Radius.circular(100.0)),
),
margin: EdgeInsets.fromLTRB(22, 15, 50, 9),
height: _height ? 80 : 0,
child: Stack(
children: <Widget>[
GestureDetector(
onDoubleTap: () {
setState(() {
_height = !_height;
});
setState(() {
items.removeAt(index);
});
},
child: Card(
color: Color(0xFF324467),
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30),
),
child: Row(
children: [
SizedBox(
height: 30,
width: 63,
child: RaisedButton(
onPressed: () {
setState(() {
_height = !_height;
});
setState(() {
items.removeAt(index);
});
},
elevation: 0,
color: Colors.transparent,
shape: CircleBorder(
side: BorderSide(
width: 2.3,
color: Colors.blue,
),
),
),
),
Padding(padding: EdgeInsets.fromLTRB(0, 0, 7, 0)),
Flexible(
child: Container(
child: Text(
items[index],
overflow: TextOverflow.fade,
style: TextStyle(
fontSize: 21,
fontWeight: FontWeight.w400,
color: Colors.white,
),
),
),
),
],
),
),
),
],
),
);
},
),
【问题讨论】:
标签: flutter listview dart animation