我创建一个列表视图,并在用户滑动列表时显示更多选项菜单,我希望在用户滑动一个列表时,所有列表视图上的其他更多选项被隐藏,这是我的列表视图代码
return new ListView.builder(
itemCount: data.length,
itemBuilder: (context, i){
return Container(
color: i % 2 != 0 ? Color.fromRGBO(0,0,0,0.05) : Colors.white,
child: SlideMenu(
child: new ListTile(
title: new Text(data[i]['name']),
subtitle: new Text(data[i]['address']),
),
menuItems: <Widget>[
new Container(
decoration: BoxDecoration(
color: Colors.blueAccent,
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(25),
topLeft: Radius.circular(25)
),
),
child: new IconButton(
icon: new Icon(Icons.edit, color: Colors.white,),
onPressed: (){
},
),
),
new Container(
color: Colors.redAccent,
child: new IconButton(
icon: new Icon(Icons.delete, color: Colors.white),
onPressed: (){},
),
),
],
)
);
},
);
这是可处理滑动手势的slideMenu类
class SlideMenu extends StatefulWidget {
final Widget child;
final List<Widget> menuItems;
SlideMenu({this.child, this.menuItems});
@override
_SlideMenuState createState() => new _SlideMenuState();
}
class _SlideMenuState extends State<SlideMenu> with SingleTickerProviderStateMixin {
AnimationController _controller, _all;
@override
initState() {
super.initState();
_controller = new AnimationController(vsync: this, duration: const Duration(milliseconds: 200));
}
@override
dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final animation = new Tween(
begin: const Offset(0.0, 0.0),
end: const Offset(-0.2, 0.0)
).animate(new CurveTween(curve: Curves.decelerate).animate(_controller));
return new GestureDetector(
onHorizontalDragUpdate: (data) {
// we can access context.size here
setState(() {
_controller.value -= data.primaryDelta / context.size.width;
});
},
onHorizontalDragEnd: (data) {
if (data.primaryVelocity > 300){
_controller.animateTo(.0); //close menu on fast swipe in the right direction
}
else if (_controller.value >= .5 || data.primaryVelocity < -500){ // fully open if dragged a lot to left or on fast swipe to left
_controller.animateTo(1.0);
}
else // close if none of above
_controller.animateTo(.0);
},
child: new Stack(
children: <Widget>[
new SlideTransition(position: animation, child: widget.child),
new Positioned.fill(
child: new LayoutBuilder(
builder: (context, constraint) {
return new AnimatedBuilder(
animation: _controller,
builder: (context, child) {
return new Stack(
children: <Widget>[
new Positioned(
right: .0,
top: .0,
bottom: .0,
width: constraint.maxWidth * animation.value.dx * -1.5,
child: new Container(
child: new Row(
children: widget.menuItems.map((child) {
return new Expanded(
child: child,
);
}).toList(),
),
),
),
],
);
},
);
},
),
)
],
),
);
}
}
我该如何解决这个问题?用户滑动列表时如何隐藏其他更多选项菜单?,非常感谢您的帮助。