【发布时间】:2018-10-13 20:06:26
【问题描述】:
我需要在 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 在行元素上,则提供选择多行的能力。选择后,然后对行执行自定义操作(这不是问题的一部分:))选择后我想象一个索引数组,我可以将其传递给函数以进行进一步处理。我只需要关于多项元素选择的帮助。
【问题讨论】:
-
onLongPress() 触发。你试过了吗?我试过没有动画部分,它可以工作
-
嗨 Napolean,是的,它会触发......如果我在其中分配一个函数,它会触发,但我需要实现选择功能......这是我的堆栈
标签: android row flutter long-press