Flutter App Lifecycles For Designers
--
One of the most confusing ideas transitioning from Android and/or iOS is to understand how Flutter handles its application lifecycle.
Where’s my onCreate()? Where’s my viewDidLoad()? Why is the Sky Dark Purple? What? Not everyone’s sky is purple? Why not!
The Google Android Application Lifecycle
In Android Native Application Development, the Activity is actually most of the Application lifecycle with such methods as:
- onCreate
- onStart
- onResume
- onPause
- onStop
- onRestart
- onDestroy
And the pain part was the business logic ending up in the onCreate among other pains.
The Apple iOS Application Lifecycle
With Apple iOS native application development, the lifecycle of an UIController is:
- viewDidLoad
- viewWillAppear
- viewDidAppear
- viewWillDisappear
- viewDidDisappear
- viewDidUnload
As you can see, both platform use the same (almost) amount of steps to create and destroy a screen. viewDidLoad() will hold a lot of our business logic and the Will/Did Appear/Disappear ones are great to save information, know when the user is leaving the screen, etc.
Flutter Application Lifecycle
Now, this would not be a Fred Grott Flutter Article without a set of free tools, would it? So let’s introduce the tools.
First up, we need a little logging infrastructure, as we should not be using debugPrint or Print methods to get an output of state changes. So we have app vars, build modes, and the logging functions: