flutter-in-action
flutter-in-action copied to clipboard
关于第八章第一节 “原始指针事件 ” 中“透明组件”概念模糊
“透明组件” 只是表述的不可见组件,容易引起误解!适当的表述可以是:命中测试失败(hitTest)的组件,如果透明组件hitTest成功,translucent 与 opaque 的特性将无效!比如使用#DecoratedBox# 来包装子组件,设置透明度为0,也是不可见,反例如下,修改此节translucent 测试代码为: Stack( children: <Widget>[ Listener( child: ConstrainedBox( constraints: BoxConstraints.tight(Size(300.0, 200.0)), child: DecoratedBox( decoration: BoxDecoration( color: Color.fromARGB(255, 255, 1, 1))), ), onPointerDown: (event) => print("down0"), // behavior: HitTestBehavior.opaque, ), Listener( child: ConstrainedBox( constraints: BoxConstraints.tight(Size(200.0, 100.0)), child: DecoratedBox( decoration: BoxDecoration( color: Color.fromARGB(0, 0, 0, 0)), child: Center( child: Text("左上角200*100范围内非文本区域点击"), ), )), onPointerDown: (event) => print("down1"), behavior: HitTestBehavior.translucent //放开此行注释后可以"点透" ) ], ),
赞同,我也是在这里纠结了很久。