flutter - Flutter [animations] OpenContainer如何检测动画是否完成
问题描述
我正在使用OpenContainer animation
打开一个屏幕,该屏幕可以在打开屏幕时显示警报对话框 - 屏幕尝试显示的项目的情况不再有效或被删除。
因为 OpenContainer 在动画期间渲染屏幕,所以会多次显示警告对话框。
我试图解决这个问题是修改OpenContainer buildPage
方法以将动画状态返回给openBuilder
回调。在不修改OpenContainer
代码的情况下有更好的方法吗?
child: AnimatedBuilder(
animation: animation,
builder: (BuildContext context, Widget child) {
if (animation.isCompleted) {
return SizedBox.expand(
child: Material(
color: openColor,
elevation: openElevation,
shape: openShape,
child: Builder(
key: _openBuilderKey,
builder: (BuildContext context) {
return openBuilder(context, closeContainer, false); // added false
},
),
),
);
}
重现问题的代码 - https://gist.github.com/MartinJLee/0992a986ad641ef5b4f477fb1ce69249
解决方案
I was able to do using the following code on the container for openBuilder.
void initState() {
super.initState();
WidgetsBinding.instance
.addPostFrameCallback((_) => yourFunction(context));
}
see original answers - Flutter: Run method on Widget build complete
推荐阅读
- c# - 返回不正确的输出
- vector - 推入 STL 向量中的元素,但在使用“at”时未找到
- ios - 如何将一组自定义类转换为数据?
- sql - 如何从单个表中提取具有“共享”外键的条目
- drop-down-menu - 如何在(Asp.net Core - MVC)中从数据库创建下拉列表?
- installation - 如何仅安装 Hyperledger Fabric 的二进制文件?
- angular7 - 有人将 videojs-record 与 Angular 7 集成在一起吗?
- c# - 计算和访问列表列表中的项目,即:带有行项目的发票
- node.js - 无论如何可以安全地清理本地 Firebase 项目文件夹吗?
- spring - 在 apache 骆驼路由中使用配置属性