Junior — Middle
Can you name the main abstract concepts and components used in Flutter for creating interfaces?
sobes.tech AI
Answer from AI
In Flutter, the following core abstract concepts and components are used to create interfaces:
- Widget — the basic building block of the interface. Everything in Flutter is a widget: buttons, text, containers, even the app structure.
- StatelessWidget — a widget without state that does not change after being built.
- StatefulWidget — a widget with state that can change during the app's runtime.
- BuildContext — an object that provides information about the widget's location in the widget tree.
- Element — the link between a widget and the render object, managing the widget's lifecycle.
- RenderObject — responsible for rendering and positioning elements on the screen.
Example of a simple StatefulWidget:
class MyCounter extends StatefulWidget {
@override
_MyCounterState createState() => _MyCounterState();
}
class _MyCounterState extends State<MyCounter> {
int _count = 0;
void _increment() {
setState(() {
_count++;
});
}
@override
Widget build(BuildContext context) {
return Column(
children: [
Text('Count: \\$_count'),
ElevatedButton(onPressed: _increment, child: Text('Increment')),
],
);
}
}