Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know when the app is loaded in Flutter?

Tags:

flutter

dart

In my flutter app I'm playing an animation. And I want to start the playback only after all the widgets on the page have loaded. Essencially I'm looking for the JS equivalnat of window.onload in flutter. Right now the animation starts as soon as it can and the result it that when the app lunches I see a white screen while the app is loading for a few seconds and when the app is finally loaded the animation is already half way through the playback.

Is there a signal or event in flutter that will let me know that the app has loaded?

like image 957
Curtwagner1984 Avatar asked Oct 23 '25 14:10

Curtwagner1984


1 Answers

In a widget you can use

WidgetsBinding.instance.addPostFrameCallback((_){
  //stuff
})

If you put this in your initState the callback will be called after the first frame is rendered, if that's what you need.

like image 182
magicleon94 Avatar answered Oct 25 '25 04:10

magicleon94