Using a Timer to Switch Displayed Widgets

Onuoha Obinna
1 min readNov 3, 2021

--

First we show this, then we show that πŸ˜ƒ

In this short article I will show you how to use the dart timer class to switch between two different widgets in flutter.

Most times we want to switch between two widgets being displayed after a specified time duration has passed. This can be easily implemented using a simple combination of the dart timer and a conditional expression.

The stateful widget has a timer in its initState so that whenever the Widget is added to the widget tree the counter starts reading immediately.

When the timer elapses, the boolean value switchDisplay used to control the displayed Widget updates its state.

To use this Delayed switching widget anywhere in your App all you have to do is simply to parse the initialChild to be displayed and the finalChild to be displayed.

You can also tweak the duration between displays easily by updating the time on the DelayedDisplay Container.

visit my github

--

--

Onuoha Obinna
Onuoha Obinna

No responses yet