【发布时间】:2020-11-20 02:21:34
【问题描述】:
这是我在 Flutter 中定义的 GestureDetector:
return GestureDetector(
behavior: HitTestBehavior.opaque,
onHorizontalDragStart: _onHorizontalDragStart,
onHorizontalDragUpdate: _onHorizontalDragUpdate,
onHorizontalDragEnd: _onHorizontalDragEnd,
child:
Container(
color: Theme
.of(context)
.scaffoldBackgroundColor,
child: Padding(
padding: const EdgeInsets.all(
16.0,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
InkWell(
onTap: () => launchUrl(item.link),
child: Padding(
padding: const EdgeInsets.only(bottom: 8.0),
child: Container(
child: Text(
item.title == "" ? "Comment" : item.title,
style: Theme
.of(context)
.textTheme
.headline5
.copyWith(
fontWeight: FontWeight.w600,
),
),
),
),
),
Padding(
padding: const EdgeInsets.only(bottom: 8.0),
child: InkWell(
onTap: () async {
Channel channel = await Repo.fetchChannelItem(int.parse(item.subSourceId));
Navigator.push(
context,
MaterialPageRoute(builder: (context) => ChannelPage(item:channel)),
//ProfilePage(username: item.author))
);
}, child: Text(
item.domain,
style: Theme
.of(context)
.textTheme
.caption,
)
),
),
if (item.content != "")
if (item.parts.isNotEmpty)
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
],
),
],
),
),
));
}
此页面显示了一些文章内容,但有时文章很短,并在页面按钮中留出一些空间。在这种情况下,当拖动页面的空白区域时,GestureDetector 手势不起作用。我读过这个https://stackoverflow.com/questions/59062264/how-to-make-gesturedetector-also-work-when-touch-empty-space-in-flutter。并在 GestureDetector 中添加这一行:
behavior: HitTestBehavior.opaque,
还是不行,那么当拖动这个页面的空白处时,我应该怎么做才能使拖动事件起作用呢?现在我正在使用flutter Inspector 检查小部件,发现 GestureDetector 区域小于子子区域容器:
如何扩大GestureDetector效果区域?
【问题讨论】:
-
如果你使用的是Android studio,你可以使用`flutter Inspector`来查看你的widget的所有位置。从那里你可以看到为什么它不工作。不确定其他 IDE
标签: flutter