Flutter Fundamentals
1. Introduction to Flutter
Flutter is an open-source UI software development toolkit created by Google. It is used to develop
cross-platform applications from a single codebase using the Dart language.
2. Flutter Architecture
Flutter apps are built using widgets. Everything in Flutter is a widget, including layout models and UI
elements.
3. Main Function and runApp()
The entry point of a Flutter app is the main() function, which calls runApp() to start the app.
Example:
void main() {
runApp(MyApp());
4. Widgets
Widgets are the building blocks of a Flutter app. There are two types:
- StatelessWidget: for static UI
- StatefulWidget: for dynamic UI
Example:
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('Hello Flutter')),
body: Center(child: Text('Welcome to Flutter')),
),
);
5. Layouts
Flutter uses widgets for layout as well, such as Column, Row, Container, Padding, etc.
Example:
Column(
children: [
Text('Item 1'),
Text('Item 2'),
],
6. Navigation
Flutter provides a Navigator for navigating between screens.
Example:
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondScreen()),
);
7. State Management
Managing state is crucial in Flutter. Common methods include:
- setState()
- Provider
- Riverpod
- Bloc
8. Hot Reload
Flutter supports hot reload, which allows developers to see changes instantly without restarting the
app.
9. Packages and Plugins
Flutter has a rich ecosystem of packages available through pub.dev to extend functionality (e.g.,
HTTP requests, local storage, Firebase).
10. Building and Running Apps
Use the Flutter CLI to build and run apps:
- flutter create my_app
- flutter run
- flutter build apk / ios