我有一堆这样放置的容器:
我想水平滚动它们,并相应地将该容器带到前面,即当向右滚动时,将蓝色的带到前面,当向左滚动时,将黄色的带到前面.
Something like this but a scroll instead of clicks:
我试着使用带有水平滚动的SingleChildScrollView,但不出所料,它不起作用.我try 的代码是:
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Stack(
clipBehavior: Clip.none,
children: [
Container(),
Positioned(
top: 145.h,
left: 100.w,
height: 300.h,
width: 250.w,
child: ElevatedButton(
onPressed: () {},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
elevation: 3.h,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(5.r), //// <-- Radius
),
),
child: Text("pp"),
),
),
Positioned(
top: 145.h,
left: 20.w,
height: 300.h,
width: 250.w,
child: ElevatedButton(
onPressed: () {},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.yellow,
elevation: 3.h,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(5.r), //// <-- Radius
),
),
child: Text("Demo 3"),
),
),
Positioned(
top: 145.h,
left: 60.w,
height: 300.h,
width: 250.w,
child: ElevatedButton(
onPressed: () {},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red,
elevation: 3.h,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(5.r), //// <-- Radius
),
),
child: Text(
"Demo 2",
style: TextStyle(
fontSize: 20.sp,
fontWeight: FontWeight.w500,
),
),
),
),
Positioned(
top: 145.h,
left: 60.w,
height: 300.h,
width: 250.w,
child: ElevatedButton(
onPressed: () {},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red,
elevation: 3.h,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(5.r), //// <-- Radius
),
),
child: Text(
"Demo",
style: TextStyle(
fontSize: 20.sp,
fontWeight: FontWeight.w500,
),
),
),
),
],
),
我知道的一个解决方案是使用墨水井,并使用ONTAP/ElevatedButton onPress来调整定位并将相应的容器放在前面,但用户体验不会像水平滚动一样好.
我还try 使用带有RotatedBox的ListWheelScrollView来模拟水平滚动,但效果不够好.
任何在这方面的帮助都将不胜感激!