I have to shift my widget in stack by (size of screen - size of widget A which I can obtain from key). Both values are available only after build, but as I know I should initialize my animations in initState. Is there a way to initialize my Tween animation after build completed?
1 Answer
I see that, you need to do your operation after build. Assuming that, you have your Animation Method already to be implemented, as I can see that you're calling that in your initState() method. So, what you can do is following:
You can use Flutter After Layout Package, which executes a function only one time after the layout is completed.
OR
Look at the code which you can use it to achieve the same:
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) => _myFunction(context));
}
You can use this as an alternative, for WidgetBinding in your initState():
// import this to implement the below code
import 'package:flutter/scheduler.dart';
SchedulerBinding.instance.addPostFrameCallback((_) => _myFunction(context));