Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set animation after build flutter?

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?

like image 599
Ilya Maximencko Avatar asked Jan 29 '26 09:01

Ilya Maximencko


1 Answers

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));
like image 131
Alok Avatar answered Feb 01 '26 03:02

Alok



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!