Flutter使用Stack设置clipBehavior为Clipnone溢出之后MouseRegion不生效了我需要所有的解决办法请给出解方案代码
解决方案1:使用Positioned包裹MouseRegion
可以在Stack中使用Positioned包裹MouseRegion,这样MouseRegion就不会受到Stack的clipBehavior影响了。
示例代码:
Stack(
clipBehavior: Clip.none,
children: [
Container(
width: 200,
height: 200,
color: Colors.blue,
),
Positioned(
top: 50,
left: 50,
child: MouseRegion(
cursor: SystemMouseCursors.click,
child: Container(
width: 100,
height: 100,
color: Colors.red,
),
),
),
],
)
解决方案2:使用Transform.translate包裹MouseRegion
可以在Stack中使用Transform.translate包裹MouseRegion,这样MouseRegion也不会受到Stack的clipBehavior影响。
示例代码:
Stack(
clipBehavior: Clip.none,
children: [
Container(
width: 200,
height: 200,
color: Colors.blue,
),
Transform.translate(
offset: Offset(50, 50),
child: MouseRegion(
cursor: SystemMouseCursors.click,
child: Container(
width: 100,
height: 100,
color: Colors.red,
),
),
),
],
)
解决方案3:使用OverflowBox包裹Stack
可以在Stack的外层使用OverflowBox包裹,这样Stack可以溢出父容器,而不影响MouseRegion的响应。
示例代码:
OverflowBox(
maxWidth: double.infinity,
maxHeight: double.infinity,
child: Stack(
clipBehavior: Clip.none,
children: [
Container(
width: 200,
height: 200,
color: Colors.blue,
),
MouseRegion(
cursor: SystemMouseCursors.click,
child: Container(
margin: EdgeInsets.only(top: 50, left: 50),
width: 100,
height: 100,
color: Colors.red,
),
),
],
),
)
原文地址: http://www.cveoy.top/t/topic/bfw1 著作权归作者所有。请勿转载和采集!