Flutter UI Architecture
Understanding the widget tree
Flutter describes UI as a tree of widgets. A widget is an immutable configuration; State objects hold mutable state for StatefulWidget.
BuildContext
BuildContext identifies a widget location in the tree. It is used to access inherited data such as Theme, MediaQuery and Provider. Avoid retaining a context longer than the widget lifecycle requires.
dart
class Greeting extends StatelessWidget {
const Greeting({super.key});
@override
Widget build(BuildContext context) {
return Text(
'Welcome',
style: Theme.of(context).textTheme.headlineSmall,
);
}
}Lesson complete?Use the next lesson to continue the learning path.