我需要在 Flutter for Android 和 iOS 的行元素上实现长按选择。有什么帮助吗?
我的代码到目前为止:
class ListElement extends StatelessWidget {
ListElement({this.text, this.name, this.mId, this.animationController});
final String text;
final String name;
final String mId;
final AnimationController animationController;
@override
Widget build(BuildContext context) {
return new GestureDetector(
onTap: () {
Navigator.of(context).push(
new MaterialPageRoute(builder: (BuildContext context) => new DrugProfile(drugmId))
);
},
onLongPress: () {
//HERE I NEED TO SELECT MULTIPLE ROWS IF IT FIRES
},
child: new SizeTransition(
sizeFactor: new CurvedAnimation(
parent: animationController, curve: Curves.easeOut),
axisAlignment: 0.0,
child: new Container(
margin: const EdgeInsets.symmetric(vertical: 10.0),
child: new Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Container(
margin: const EdgeInsets.only(right: 16.0),
child: new CircleAvatar(child: new Text(name[0].toUpperCase())),
),
new Expanded(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Text(name, style: Theme.of(context).textTheme.subhead),
new Container(
margin: const EdgeInsets.only(top: 5.0),
child: new Text(
text,
textAlign: TextAlign.left,
style: new TextStyle(
fontSize: 13.0,),
),
),
],
),
),
],
),
)
)
);
}
}
也许我从 onLongPress 事件开始是错的,但我需要做以下事情:如果 longPress 在一个行元素上,那么提供选择许多行的能力。选择之后然后对行执行自定义操作(这不是问题:)的一部分)选择后我想象一个索引数组,我可以将其传递给函数以进行进一步的处理。我只需要多个元素选择的帮助。