flutter - Flutter 中的动画浮动操作按钮
问题描述
我正在尝试添加动画,当用户向下滚动时,工厂将动画出来并消失,当向上滚动时,工厂再次出现。
这是我的代码:
return Scaffold(
floatingActionButton: AnimatedContainer(
curve: Curves.easeIn,
duration: const Duration(seconds: 1),
child: Opacity(
opacity: _fabVisible ? 1 : 0,
child: FloatingActionButton(
onPressed: () {},
child: Icon(
Icons.add,
color: Colors.black,
),
backgroundColor: Colors.white,
),
),
),
代码现在正在做的是工厂正确隐藏,但它不会为不透明度设置动画,它只是在没有动画的情况下弹出和弹出,请帮助!
谢谢你
解决方案
尝试使用scrollnotification来检测向下滚动(增加像素)和向上滚动(减少像素),向下滚动时,setState _fabVisible = 0,反之亦然:
Expanded(
child: NotificationListener<ScrollNotification>(
onNotification: (scrollNotification) {
if (scrollNotification is ScrollStartNotification) {
_onStartScroll(scrollNotification.metrics);
} else if (scrollNotification is ScrollUpdateNotification) {
_onUpdateScroll(scrollNotification.metrics);
} else if (scrollNotification is ScrollEndNotification) {
_onEndScroll(scrollNotification.metrics);
}
},
child: ListView.builder(
itemCount: 30,
itemBuilder: (context, index) {
return ListTile(title: Text("Index : $index"));
},
),
),
),
_onStartScroll(ScrollMetrics metrics) {
setState(() {
message = "Scroll Start";
});
}
_onUpdateScroll(ScrollMetrics metrics) {
setState(() {
message = "Scroll Update";
});
}
_onEndScroll(ScrollMetrics metrics) {
setState(() {
message = "Scroll End";
});
}
推荐阅读
- python - 如何从字符串列表中创建一个 DataFrame,每个字符串具有不同数量的属性
- javascript - 如何在描述块中并行或一个接一个地运行 webdriverio it 语句?
- excel - 循环 vba 代码,使其在工作簿中工作多个工作表
- python - 根据列索引添加行
- python - 如何在二维列表中查找与特定模式匹配的元素
- 2d - 什么是 2D 中的人脸?
- php - 如何使用带有 Php Ajax 的 Jquery Tabledit 插件使用数据库填充下拉列表
- python - 将数组元素作为一行附加到文件中
- android - 清除android back stack会清除firestore缓存吗?
- javascript - Iframed 内容通过 SCORM / xAPI 与 LMS 通信?