Types of Widget

As you might have guessed based on the topic of this post, each widget in flutter is either a Stateful Widget or a Stateless Widget

Both widgets differ in only one aspect which is the ability to reload the widget at runtime.

This subtle difference plays a huge role in building interactive flutter applications. Let’s see what exactly it means.

Stateless Widgets

We create a Stateless widget by extending our class from StatelessWidget and a bare minimum implementation shall look like

A bare minimum stateless widget

Here MyApp is a StateLessWidget and the each and every widget has to override the function called Widget build(BuildContet context) which returns one or more widgets.

So whenever MyApp is instantiated, it will call the build(...) function and draw the widgets returned by this function.

Stateless Widget are immutable once drawn (i.e build)

The build(...) function of the StateLessWidget is called only ONCE and no amount of changes in any Variable(s), Value(s) or Event(s) can call it again.