Junior — Middle
Can you tell about different types of user interface components you know?
sobes.tech AI
Answer from AI
In Flutter, there are many user interface components (widgets) that can be conditionally divided into several types:
- Standard widgets — basic interface elements such as
Text,Button,Image,Icon,Container. - Stateful widgets (StatefulWidget) — widgets that can change their state during the application's operation.
- Stateless widgets (StatelessWidget) — widgets that do not have internal state and only display the passed data.
- Composite widgets — widgets composed of other widgets, such as
Column,Row,Stackfor layout. - Interactive widgets — buttons, switches, checkboxes, input fields (
TextField) that respond to user actions. - Complex widgets — for example,
ListView,GridViewfor displaying lists and grids with scrolling.
Example of a simple stateful widget:
class CounterWidget extends StatefulWidget {
@override
_CounterWidgetState createState() => _CounterWidgetState();
}
class _CounterWidgetState extends State<CounterWidget> {
int _counter = 0;
void _increment() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Column(
children: [
Text('Counter: \\$_counter'),
ElevatedButton(onPressed: _increment, child: Text('Increase')),
],
);
}
}