A widget that require Immutable state i.e. the widgets state cannot be modified after it is created.
Stateless widget are useful when the part of the user interface only depends on the configuration information in the object itself and the BuildContext
in which the widget is inflated.
BuildContext: A handle to the location of a widget in the widget tree.
Extend a class with StatelessWidget.
class StatelessWidgetDemo extends StatelessWidget {
Widget build(BuildContext context) {
//...
}
}
This example shows how to implement Stateless widgets.
import 'package:flutter/material.dart';
class StatelessWidgetDemo extends StatelessWidget {
Widget build(BuildContext context) {
return Center(
child: Text(
'Hello, world!',
textDirection: TextDirection.ltr,
));
}
}
void main() {
runApp(StatelessWidgetDemo());
}