From StatefulWidget to ReactiveWidget

Aymen Toumi
1 min readOct 5, 2018

--

If you search for an easy alternative to flutter StatefulWidget you are in the right place.

From the first day I start learning flutter, I always thinking why StatefulWidget must be used to change widget property, for example the Text widget content, and why I can’t do this with a StatelessWidget.

From that time, I keep trying to make StatelessWidget reactive and here where I’m now.

I wrote this class called ReactiveWidget which is based on StatelessWidget and that can be used instead of StatefulWidget :

To make things clear, let’s change the Flutter default app, the famous counter app that you get when a new Flutter project is created. First, let’s turning the needed widget to a reactive one.

Now, what if we like to toggle AppBar color when FloatingActionButton pressed for that we need a CustomAppBar like this:

Now, MyHomePage widget can be a StatelessWidget.

Guess that’s help, don’t hesitate to drop a comment we all here to learn.

--

--