Stateless vs Stateful widget lifecycle in Flutter

Anmol Gupta
4 min readApr 10, 2022

Difference

This blog will learn about stateless and stateful widgets’ lifecycle. We shall learn about all the methods that are used to maintain the lifecycle of the stateful widgets. So let’s get started.

Stateless Widget:

  1. Stateless widgets are those widgets whose state can’t be changed or altered once they are built.
  2. These widgets are immutable once they are built.
  3. Any change in data, widgets, icons, or variables do not change the state of the app or UI.
  4. They simply override the build() method and return a widget.

Example:

import 'package:flutter/material.dart';void main() => runApp(MyApp());class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container();
}
}

Stateful widget:

  1. Stateful widgets are those widgets whose state can be changed in real-time.
  2. Stateful widget overrides the createState() and returns a state.
  3. They are dynamic in nature.

The Lifecycle of stateful widget:

  1. createState(): When we create a stateful widget, a…

--

--