Learn to build beautiful UIs with Flutter and Dart
Flutter is a framework for building beautiful, natively compiled applications using Dart. It provides widgets - reusable UI building blocks - to create responsive interfaces.
A widget is a description of part of the user interface. Everything in Flutter is a widget:
Immutable widgets that don't change after creation. Use for static content.
``darclass MyButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Button(
onPressed: () => print('Clicked!'),
child: Text('Click Me'),
);
}
}
`Widgets that can change over time. Use for interactive content.
``darclass Counter extends StatefulWidget {
@override
State
}
class _CounterState extends State
int count = 0;
@override
Widget build(BuildContext context) {
return Column(
children: [
Text('Count: $count'),
Button(
onPressed: () => setState(() => count++),
child: Text('Increment'),
),
],
);
}
}
`Arrange children horizontally in a single line.
``darRow(
children: [
Text('Hello'),
Text('World'),
],
)
`Arrange children vertically in a single line.
``darColumn(
children: [
Text('First'),
Text('Second'),
],
)
`A box that combines common painting, positioning, and sizing widgets.
``darContainer(
width: 200,
height: 200,
color: Colors.blue,
child: Text('Hello'),
)
`Display text with optional styling.
Every Flutter app starts with a Material or Cupertino app:
``darvoid main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: HomeScreen(),
);
}
}
`Provides information about where a widget is in the widget tree. Used to:
Mutable data that can change over time. When state changes:
Flutter feature that updates code without restarting the app. Speeds up development significantly.
1. **Use Constants**: Prevent unnecessary rebuilds
2. **Extract Widgets**: Break large widgets into smaller ones
3. **Use Meaningful Names**: Make code self-documenting
4. **Handle Null Safety**: Dart requires explicit null handling
5. **Test Widgets**: Write tests for UI components