【问题标题】:How to make two tap events in ListTile?如何在 ListTile 中制作两个点击事件?
【发布时间】:2023-01-06 23:06:35
【问题描述】:

首先,我将 CustomExpansionPanelList 小部件作为父级。然后是CustomExpansionPanel 的孩子列表。在 headerBuilder 中是 ListTile,它的尾部有文本和图标。问题:onPressed事件很难被CustomExpansionPanel捕获。必须完成特定的水龙头。

enter image description here

注:CustomExpansionPanelListCustomExpansionPanel是我修改的类。删除“自定义”,您将获得小部件本身的类。

代码:

CustomExpansionPanelList(
      elevation: 0,
      expandedHeaderPadding: EdgeInsets.zero,
      expansionCallback: (i, isOpen) {
       ///some code
      },
      children: [
        CustomExpansionPanel(
          canTapOnHeader: true,
          isExpanded: true,
          body: const SomeBody(),
          headerBuilder: (context, isOpen) {
            return ListTile(
                iconColor: Colors.white,
                contentPadding: const EdgeInsets.symmetric(
                    horizontal: 20.0),
                title: const Text(
                  'some text',
                ),
                trailing: Transform.translate(
                    offset: const Offset(30, 0),
                    child: Container(
                      margin: EdgeInsets.all(8),
                      child: IconButton(
                          icon: Icon(Icons.edit_outlined),
                          onPressed: () => someAction()
                              )),
                    )));
          },
        ),
])

【问题讨论】:

    标签: flutter dart listtile


    【解决方案1】:

    ListTile提供了onTap方法,你可以使用。

    return ListTile(
      onTap: () {
        
      },
      iconColor: Colors.white,
    

    更多关于ListTile

    【讨论】:

      猜你喜欢
      • 2022-01-25
      • 1970-01-01
      • 2019-01-30
      • 1970-01-01
      • 1970-01-01
      • 2014-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多