Flutter ListTile启用多选onLongPress
发布时间:2020-12-14 14:51:21 所属栏目:百科 来源:网络整理
导读:我想实现Google Keep中类似的功能. 如何在长按时启用多个选项并更改标题按钮,以便我可以在以后删除这些选定的项目? 我目前的Dart代码: @override Widget build(BuildContext context) { return new Card( child: new Column(mainAxisSize: MainAxisSize.mi
我想实现Google Keep中类似的功能.
如何在长按时启用多个选项并更改标题按钮,以便我可以在以后删除这些选定的项目? 我目前的Dart代码: @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,) ]),); } 解决方法
当用户长按时,ListTile必须将所选属性更改为true,反之亦然,卡颜色必须更改为像
Grey[300]这样的东西
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; } }); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
热点阅读