Expanded
是自动扩展布局,它可以用于Row
, Column
或Flex
布局中。Expanded
部件会尝试占用尽可能多的空间。
但是在GestureDetector中,点击事件会无效:
解决方法
给GestureDetector包裹的最外层Widget加一个背景色:
GestureDetector(
onTap: onTap,
child: Container(
color: Colors.transparent,
height: 50,
margin: const EdgeInsets.only(left: 10, right: 10),
child: Stack(
alignment: Alignment.center,
children: [
Row(
children: <Widget>[
Image.asset(image),
Container(
margin: const EdgeInsets.only(left: 10),
child: Text(
title,
style: const TextStyle(fontSize: 16),
),
),
Expanded(child: Container()), //自动扩展挤压
Image.asset(
'assets/images/community_icon_right.png',
width: 20,
)
],
),
],
),
),
);