A Better Flutter App #7

I Like Screenshots. Tap Caption For Gists.

As always, I prefer using screenshots in my articles over gists to show concepts rather than just show code. I find them easier to work with frankly. However, you can click or tap on their captions to see the code in a gist or in Github. Tap or click on the screenshots themselves to zoom in on them for a closer look.

No Moving Pictures, No Social Media

There will be gif files in this article demonstrating aspects of the topic at hand. However, it’s said viewing such gif files is not possible when reading this article on platforms like Instagram, Facebook, etc. They may come out as static pictures or simply blank placeholder boxes. Please, be aware of this and maybe read this article on medium.com

Other Stories by Greg Perry

An Eventful Lifecycle

Android developers would be familiar with and perhaps even miss the lifecycle event functions listed along the first column in the graphic below. The second column is the Flutter platform’s equivalent. In this article, I’ll introduce their implementation and use as it pertains to the starter example app.


A Time and Place for a Timer

The Timer object displays a new word-pair every two seconds — but only when viewed in the Counter app. There are two other apps in the starter example app. For efficiency, the Timer object is stopped when the user moves off the Counter app and is only started again when the user returns back.

Going Full Circle In Cycle

Coming back to the Counter app, in a very consistent and systematic way, the ‘Contacts app’ will call its controller, ContactsController, own deactivate function then soon after that, the Counter app screen is rebuilt. Therefore, the State object, _CounterPageState, is rebuilt and calls its initState() function. Of course, this means the attached controller, CounterController, own initState() function is called repeating the whole process and a list of red word-pairs is displayed once again. See how that works?

Time To Pause Then Resume

When another app, for example, is selected and the starter app is now in the background, it’s best to again stop the Timer object and its periodic processing. That’s demonstrated somewhat in the gif file below. Know that even a tap on the Android phone’s stop button causing the app to shrink back into the background will pass the value, AppLifecycleState.paused, to the didChangeAppLifecycleState() function. The cancel() function is then called as a result. See below. The Timer‘s periodic process has been stopped.

A Better Flutter App #8

Using a InheritedWidget



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store