3

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 1

7

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));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.