【发布时间】:2023-01-06 23:06:35
【问题描述】:
首先,我将 CustomExpansionPanelList 小部件作为父级。然后是CustomExpansionPanel 的孩子列表。在 headerBuilder 中是 ListTile,它的尾部有文本和图标。问题:onPressed事件很难被CustomExpansionPanel捕获。必须完成特定的水龙头。
注:CustomExpansionPanelList和CustomExpansionPanel是我修改的类。删除“自定义”,您将获得小部件本身的类。
代码:
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()
)),
)));
},
),
])
【问题讨论】: