Member-only story

Stateless and Stateful Widgets in Flutter

Jangwook Kim
2 min readFeb 2, 2023

In Flutter, there are two types of widgets. I want to know about that 2 widgets.

Introduction

In Flutter, there are two types of widgets: stateless and stateful. Both are used to create user interfaces, but they each have different capabilities. Stateless widgets are static and can’t change over time. Stateful widgets, on the other hand, can have their properties updated over time, or have their state changed.

StatelessWidget

A stateless widget is a widget that does not require any state to be managed. It is immutable and can’t change over time. These widgets are the simplest to understand and are often the best choice for simple UI elements.

For example, if you have a button that doesn’t change its appearance, you could create it using a stateless widget. The code might look something like this:

class MyButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
return RaisedButton(
child: Text('My Button'),
onPressed: () {
// Do something when the button is pressed
},
);
}
}

StatefulWidget

Stateful widgets, on the other hand, can change over time. The state of the widget is managed internally, and the widget…

--

--

Jangwook Kim
Jangwook Kim

Written by Jangwook Kim

Korean, live in Japan. The programmer. I love to learn something new things. I’m publishing my toy projects using GitHub. Visit https://www.jangwook.net.

No responses yet