Flutter Stateless and Stateful Widget

Paridhi Kothari
3 min readNov 27, 2018

--

What is Stateless Widget?

A widget that does not require mutable state. See below image :

What that means is that when we create a button on the screen or a text widget on a screen they really don’t have a state which means they don’t need to be drawn on the screen. When we are just putting them on the screen which means if you put a button on the screen just a simple button and do not reload or run the application each time you’re running this application. The state doesn’t change because there is no internal state for this but because there is no need to redraw them when something happens.

Stateless Widget

Now, If we talked about textfield. Textfield allows us to enter some text they Paridhi when we enter some text is that we need to save a state.

Another example would be a slider’s as lighter allows us to slide left or right as we slightly slider’s is that we are changing the state of the slider right. So the values are changing and most often we want to be able to save those states.

So a stateful widget saves internal state which means there is a process of redrawing those widgets. The way it is stateful Widger works is very simple.

Stateful widget Slider

Take example of a slider for instance so a slider when we slide left or right slider will be the state or the event. What happens is internally there is this set state method of function that is called. So what this one does internally what happens is it allows to change the values of the slider Let’s see if you’re in zero. If you could write goes to one or 10 or 15 and so forth. So it’s storing the state of this current state as we move left or right of the slider is storing those state into a state object. So every stateful widget has this object called the state object which all it does is to store state objects.

So when that happens the state object returns the current state has been saved. Let’s say the value is 1 back to the said state which then will go ahead and redraw our user interface.

Ok so a good example would be if you had an application that perhaps is when you tap on a button we want to change the state of a text or a slider or the entire redrawing of the entire swing.

This is what happens so you go through the set state which knows how to populate or save the state into an object called the state object in the state object then we’ll push or send those values that are needed to redraw the widgets on the screen.

Thanks for Reading :-)

--

--