Flutter 颤振列表TILE启用多选onLongPress
我想在Google Keep中实现类似的功能 如何在长按时启用多个选择并更改标题按钮,以便以后删除这些选定的项目 我当前的Dart代码:Flutter 颤振列表TILE启用多选onLongPress,flutter,Flutter,我想在Google Keep中实现类似的功能 如何在长按时启用多个选择并更改标题按钮,以便以后删除这些选定的项目 我当前的Dart代码: @override Widget build(BuildContext context) { return new Card( child: new Column(mainAxisSize: MainAxisSize.min, children: <Widget>[ new ListTile(
@override
Widget build(BuildContext context) {
return new Card(
child: new Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
new ListTile(
leading: const Icon(Icons.info),
title: new Text(item.name),
subtitle: new Text(item.description),
trailing: new Text(item.dateTime.month.toString()),
onTap: () => _openEditDialog(context, item),
onLongPress: // what should I put here,
)
]),
);
}
@覆盖
小部件构建(构建上下文){
归还新卡(
子项:新列(mainAxisSize:mainAxisSize.min,子项:[
新ListTile(
前导:常量图标(Icons.info),
标题:新文本(项目名称),
字幕:新文本(项目说明),
尾随:新文本(item.dateTime.month.toString()),
onTap:()=>\u openedit对话框(上下文,项),
onLongPress://我应该在这里放什么,
)
]),
);
}
当用户长按时,必须将所选属性更改为true,反之亦然,并且卡的颜色必须更改为类似的颜色
哦,好的。。这意味着我需要自己实现框样式和标题。。我认为这有一个简单的配置。。thanks@Mrye,您是否成功地重新创建了您想要执行的操作(先长按进行第一次选择,然后单按ontap选择其他操作)?如果是这样的话,你介意展示一下吗?Thanks@David我已经为此使用了inheritedwidget。。但我不确定最好的方法。。根据这个短片和代码,我必须长按所有三个选项卡来选择其中的每一个,但所需的行为是:我长按一次,然后点击其他任何一个来添加或删除选择
class cardy extends StatefulWidget {
@override
_cardyState createState() => new _cardyState();
}
class _cardyState extends State<cardy> {
var isSelected = false;
var mycolor=Colors.white;
@override
Widget build(BuildContext context) {
return new Card(
color: mycolor,
child: new Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
new ListTile(
selected: isSelected,
leading: const Icon(Icons.info),
title: new Text("Test"),
subtitle: new Text("Test Desc"),
trailing: new Text("3"),
onLongPress: toggleSelection // what should I put here,
)
]),
);
}
void toggleSelection() {
setState(() {
if (isSelected) {
mycolor=Colors.white;
isSelected = false;
} else {
mycolor=Colors.grey[300];
isSelected = true;
}
});
}
}
void toggleSelection() {
setState(() {
if (isSelected) {
border=new BoxDecoration(border: new Border.all(color: Colors.white));
mycolor = Colors.white;
isSelected = false;
} else {
border=new BoxDecoration(border: new Border.all(color: Colors.grey));
mycolor = Colors.grey[300];
isSelected = true;
}
});
}