HitTestBehavior 是一个枚举
enum HitTestBehavior {
/// Targets that defer to their children receive events within their bounds
/// only if one of their children is hit by the hit test.
deferToChild,
/// Opaque targets can be hit by hit tests, causing them to both receive
/// events within their bounds and prevent targets visually behind them from
/// also receiving events.
opaque,
/// Translucent targets both receive events within their bounds and permit
/// targets visually behind them to also receive events.
translucent,
}
- deferToChild
deferToChild: 命中测试决定于子组件是否通过命中测试
- opaque
顾名思义不透明的,也就是说自己接收命中测试,但是会阻碍前兄弟节点进行命中测试
- translucent
顾名思义半透明,也就是说自己可以命中测试,但是不会阻碍前兄弟节点进行命中测试
demo 测试
import 'package:flutter/material.dart';
class HitTestWidget exte

文章详细解释了Flutter中的HitTestBehavior枚举在处理触摸事件时的不同行为:deferToChild、opaque和translucent。通过示例代码展示了不同行为在有颜色和无颜色的容器中如何影响点击事件的传递和处理。并深入到渲染对象的层次分析了行为背后的原因。
最低0.47元/天 解锁文章
937

被折叠的 条评论
为什么被折叠?



