首页 > 解决方案 > 如何使 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. 处理此操作的最佳方法是什么?

谢谢。

标签: dartflutter

解决方案


包裹您的Icon内部InkWell以处理水龙头:

      secondary: InkWell(
                onTap: () {
                  print("click light");
                },
                child: const Icon(Icons.lightbulb_outline),
              ),

更多信息:https ://docs.flutter.io/flutter/material/InkWell-class.html


推荐阅读