dart - 如何使 SwitchListTile 图标可点击?
问题描述
是否有可能使Tapable的secondary
属性?SwitchListTile
在这种情况下,icon
使用 an:
SwitchListTile(
title: const Text('Lights'),
value: _lights,
onChanged: (bool value) { setState(() { _lights = value; }); },
secondary: const Icon(Icons.lightbulb_outline), //can this be selected?
)
理想情况下,我不想创建另一个小部件,而是想在用户选择它时使用Icon
属性中的secondary
来显示一条消息。
Currently when the icon, or entire widget is selected, the switch is toggled. 处理此操作的最佳方法是什么?
谢谢。
解决方案
包裹您的Icon
内部InkWell
以处理水龙头:
secondary: InkWell(
onTap: () {
print("click light");
},
child: const Icon(Icons.lightbulb_outline),
),
更多信息:https ://docs.flutter.io/flutter/material/InkWell-class.html
推荐阅读
- powershell - 如何修复访问权限不足错误?
- python - Python JSON 序列化字典
- javascript - 有人能解释一下为什么我们在 javaScript 中的条件周围使用括号吗
- java - 如何解析结果集的 .equals 函数的值?
- jquery - 有没有办法我可以干掉这段代码或使用更好的方法来实现这种切换效果
- reactjs - 在 React 中找不到模块 TS2307
- visual-studio-code - 如何使 VS Code 的“向上移动”(或向下)功能自动应用适当的缩进,如 Atom?
- c# - 如何将自定义按钮添加到 Outlook?
- google-maps - 如何获取原始交通流量数据
- excel - 如何在 VBA 中使用公式