我正在尝试使用堆栈创建一个多层屏幕,该堆栈允许用户与前台和后台小部件进行交互。
我已经开始绘制屏幕的基本轮廓,但是即使使用HitTestBehavior.translucent控制台,也仅red pressed在按下半透明红色容器时打印。我希望控制台在按下红色/紫色容器时打印两个字符串。
下面是我使用的代码。
@override
Widget build(BuildContext context) {
final children = <Widget>[
GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () {
debugPrint('blue pressed');
},
child: Container(
height: 500,
width: MediaQuery.of(context).size.width,
color: Colors.blue,
),
),
];
if (exercise.instructions.isNotEmpty) {
children.add(
GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () {
debugPrint('red pressed');
},
child: Container(
height: 400,
width: MediaQuery.of(context).size.width,
color: Colors.red.withAlpha(100),
),
),
);
}
return Stack(
alignment: Alignment.bottomCenter,
children: children,
);
}
Run Code Online (Sandbox Code Playgroud)
下面是制作出来的画面: