flutter - 带有拖动手势的颤动动画底部抽屉
问题描述
所以,我正在尝试制作一个发射器并努力应对这种拖动效果。如果我从屏幕上的任意位置点击并向上拖动,抽屉就会开始打开。如果可能的话,任何人都可以解释或编码这种效果吗?我尝试了一些东西,但它并不是那么顺利
我试过这个,但它不是很顺利
double customHeight;
bool animationEnded;
@override
void initState() {
super.initState();
animationEnded = true;
customHeight = 0;
}
@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return Scaffold(
appBar: AppBar(
title: Text("Live Test"),
),
body: GestureDetector(
onPanEnd: (details) {
if (customHeight < size.height / 2) {
animationEnded = true;
setState(() {
customHeight = 0;
});
} else {
animationEnded = true;
setState(() {
customHeight = -size.height;
});
log("opening full");
}
// log("onpanend ${details.velocity}");
},
onPanUpdate: (DragUpdateDetails details) {
if (animationEnded) {
animationEnded = false;
setState(() {
customHeight += details.delta.dy;
});
} else {
customHeight += details.delta.dy;
}
},
child: Stack(
children: [
Positioned.fill(
child: Container(
child: Text("This is the home screen"),
)),
AnimatedPositioned(
duration: Duration(
milliseconds: 80,
),
onEnd: () {
animationEnded = true;
},
left: 0,
bottom: (-size.height - customHeight),
child: Container(
width: size.width,
height: size.height,
color: Colors.pink,
alignment: Alignment.center,
child: Text("This is the swipe up screen"),
))
],
),
),
);
}
解决方案
推荐阅读
- kubernetes - 澄清 Ingress 负载均衡器
- reactjs - 在不通过 API 服务器的情况下从客户端访问 Elasticseach 是否安全?
- verilog - 这段代码在合成时会产生多少次翻转?
- css - 保持第一个元素垂直居中,下面的下一个元素
- python - 使用 cx_Freeze 捆绑 Flask 应用程序时出现“ValueError: Invalid async_mode specified”
- spring - 不支持 Spring POST 方法
- sql - Postgres:在带有“WITH数据”的查询中使用NULLIF
- python - 范围问题,可以访问对象属性但不能访问对象实例
- amazon-web-services - API 网关:在 TEST 按钮上确定,在 Curl 上显示 500
- docker - docker login 失败:tls: server selected unsupported protocol version 301