问题代码如下:
GestureDetector(
onTap: widget.onTap,
child: Container(
// 添加背景色,不然GestureDetector-》onTap点击空白区域时不响应事件
color: Colors.transparent,
alignment: Alignment.centerLeft,
padding: EdgeInsets.only(
left: (widget.departGroup.sub?.isEmpty ?? true)
? (38 + widget.itemIndentMultiple * 15)
: 0,
right: 15),
child: Expanded(
child: Text(
((widget.departGroup.id?.isEmpty ?? true) ||
(widget.departGroup.name?.isEmpty ?? true))
? HLStrings.all
: widget.departGroup.name ?? "",
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: HLTextStyles.s14c000000w400),
),
),
)
GestureDetector子部件为Container,给它设置了Padding属性,Container内部又有Text文本小部件,当不给Container设置Color背景色时点击被Padding的空白区域不会响应onTap事件,只有点击Text文本区域会响应。
解决办法:
给Container添加背景色,不然GestureDetector-》onTap点击Text文本空白区域时不响应事件