我正在尝试创建一个容器,我可以在其中执行两个手势:onTapDown
和onTapUp
. 我想在执行时减小容器的尺寸onTapDown
。
我想要的是这样的: https ://i.imgur.com/7hW2Cn1.gifv
问题是,如果我使用 AnimatedController 我还需要调整孩子的大小,这会一团糟。
我也查看了flutter_bounce
图书馆,但我想要的不是基于持续时间的东西。如果用户保持按下状态,则容器保持按下状态。
class CustomContainerState extends State<CustomContainer> {
double width = 90.w;
double height = 35.h;
@override
Widget build(BuildContext context) {
return GestureDetector(
child: Center(
child: AnimatedContainer(
duration: Duration(milliseconds: 200),
margin: EdgeInsets.only(left: 5.w, right: 5.w),
width: width,
height: height,
child: Column(
children: [
Container(
width: 90.w,
height: 25.h,
decoration: BoxDecoration(
color: green400,
borderRadius: BorderRadius.only(topLeft: Radius.circular(5.w), topRight: Radius.circular(5.w)),
),
),
Container(
margin: EdgeInsets.only(left: 5.w, right: 5.w, top: 1.h, bottom: 1.h),
width: 90.w,
height: 8.h,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(bottomLeft: Radius.circular(5.w), bottomRight: Radius.circular(5.w)),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Text(
"Ratings",
style: TextStyle(
fontFamily: "SanFrancisco",
fontSize: 10.sp,
fontWeight: FontWeight.w400,
overflow: TextOverflow.ellipsis,
),
),
Text(
"Title",
style: TextStyle(
fontFamily: "SanFrancisco",
fontSize: 12.sp,
fontWeight: FontWeight.w600,
overflow: TextOverflow.ellipsis,
),
),
Text(
"Description",
style: TextStyle(
fontFamily: "SanFrancisco",
fontSize: 10.sp,
fontWeight: FontWeight.w400,
overflow: TextOverflow.ellipsis,
),
),
],
),
),
],
),
),
),
onTapDown: (tapDownDetails) {
setState(() {
width = 85.w;
height = 30.h;
});
},
onTapUp: (TapUpDetails) {
setState(() {
width = 90.w;
height = 35.h;
});
},
);
}
}
那么问题是如何只减少自动减少子容器的父容器?因为我也可以为孩子使用多个 AnimatedContainer 但问题是文本没有动画。