Beginner
What are Flutter widgets and how do they work?
In Flutter, everything is a widget. Widgets are the building blocks of a Flutter app’s user interface. They can be stateful (maintaining state) or stateless (not maintaining state).
Widgets work by composing small components into larger ones, allowing for a declarative UI approach:
- Stateless Widgets: Do not change over time. Example: Text, Icon.
- Stateful Widgets: Maintain state. Example: Checkbox, Slider.
Here’s a simple example of a Stateless widget:
class MyStatelessWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Text('Hello, Flutter!');
}
}