sách gpt4 ăn đã đi

Flutter 嵌套的 GestureDetector 不起作用

In lại 作者:IT王子 更新时间:2023-10-29 07:11:30 25 4
mua khóa gpt4 giày nike

各位!我有一个项目 list 。列表中的主要 Widget Đúng Card。我想将它包装在 GestureDetector 中以捕捉整张卡片上的点击事件。我在有书签图标的卡内也有 Stack。我试图将此图标包装到 GestureDetector 中,但它不起作用。

我的项目:

@ghi đè
Xây dựng tiện ích (BuildContext context) {
// TODO: implement build
return Card(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8.0)),
child: Column(
trẻ em: [
chồng(
trẻ em: [
ClickableIcon(_model._bookmarked),
Thùng chứa(
height: 128.0,
constraints: BoxConstraints(minWidth: double.infinity),
child: Image.network(_model._headerSource),
),
],
),
Thùng chứa(
height: 72,
constraints: BoxConstraints(minWidth: double.infinity),
child: Row(
trẻ em: [
Thùng chứa(
margin: const EdgeInsets.only(left: 16.0, right: 16.0),
child: CircleAvatar(
radius: 20.0,
backgroundImage: NetworkImage(_model._organizerLogo),
backgroundColor: Colors.transparent,
),
),
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
những đứa trẻ: [
Chữ(
_model._eventName,
phong cách: TextStyle(
fontSize: 15,
màu sắc: Màu sắc.đen,
fontWeight: FontWeight.w500),
textAlign: TextAlign.start,
),
SizedBox(
height: 8,
),
Chữ(
"${_model._timeStart} ${_model._guide}",
phong cách: TextStyle(
fontSize: 12,
color: Color(GoEngColors.secondaryTextColor),
fontWeight: FontWeight.w500),
)
])
],
),
)
],
),
);
}

可点击图标代码:

class _ClickableIconState extends State {
@ghi đè
Xây dựng tiện ích (BuildContext context) {
// TODO: implement build
return InkWell(
onTap: () {
print("bookmarked");
setState(() {
print("state updated");
widget.selected = !widget.selected;
});
},
con: Container(
child: Icon(widget.selected
? CustomIcon.MyFlutterApp.icon_mark_applouded_1
: CustomIcon.MyFlutterApp.icon_mark_empty_1),
alignment: Alignment.topRight,
),
);
}
}

我尝试了 GestureDetectorInkWell 但都没有给出预期的结果。我还尝试为 GestureDetector 设置一个 behaviour,但它也没有帮助。

所以我的问题是:如何让整张卡片的图标可点击剩余点击实现?谢谢!

biên tập

sử dụng IconButton thay vì Icon 没有帮助。

câu trả lời hay nhất

我认为你的堆叠顺序需要颠倒

chồng(
trẻ em: [
Thùng chứa(
height: 128.0,
constraints: BoxConstraints(minWidth: double.infinity),
child: Image.network(_model._headerSource),
),
ClickableIcon(_model._bookmarked),
],
),

请测试并告诉我它是否适合您。

关于Flutter 嵌套的 GestureDetector 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56305905/

25 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress