构建颤动后如何设置动画?

How to set animation after build flutter?

我必须将我的小部件在堆栈中移动(屏幕大小 - 我可以从键获得的小部件 A 的大小)。这两个值仅在构建后可用,但据我所知,我应该在 initState 中初始化我的动画。有没有办法在构建完成后初始化我的 Tween 动画?

我明白了,你需要做你的手术after build。假设您已经实现了动画方法,我可以看到您在 initState() 方法中调用了它。所以,你可以做的是:

You can use Flutter After Layout Package, which executes a function only one time after the layout is completed.

Look at the code which you can use it to achieve the same:

@override
void initState() {
  super.initState();
  WidgetsBinding.instance.addPostFrameCallback((_) => _myFunction(context));
}

您可以使用它作为替代方案,因为 WidgetBinding 在您的 initState():

// import this to implement the below code
import 'package:flutter/scheduler.dart';

SchedulerBinding.instance.addPostFrameCallback((_) => _myFunction(context));