Flutter3.0.3使用AnimatedSize时vsync参数废弃的替代方案
问题背景
升级Flutter至3.0.3版本后,使用AnimatedSize组件时会抛出如下废弃警告:
'vsync' is deprecated and shouldn't be used. This field is now ignored. This feature was deprecated after v2.2.0-10.1.pre.. Try replacing the use of the deprecated member with the replacement.
触发警告的示例代码:
child: AnimatedSize( vsync: this, curve: Curves.easeIn, duration: Duration(seconds: 1), child: Text("test"), ),
正确处理方案
自Flutter v2.2.0-10.1.pre版本起,AnimatedSize已经内置了动画帧同步的管理逻辑,不再需要外部手动传入vsync参数,该参数当前已经被标记为完全忽略的无效配置。
- 直接删除代码中传入的
vsync: this参数即可消除警告,不需要替换为其他配置项。
修正后无警告的代码:
child: AnimatedSize( curve: Curves.easeIn, duration: Duration(seconds: 1), child: Text("test"), ),
额外提示:如果你的State类之前仅为了给
AnimatedSize传vsync而混入了TickerProviderStateMixin或SingleTickerProviderStateMixin,确认页面内其他动画组件没有用到该Ticker能力后,可以直接移除对应的混入代码,避免无意义的资源占用。
内容的提问来源于stack exchange,提问作者Ali80
相关产品推荐
相关产品推荐

