Flutter Overview
Flutter is an open-source UI software development kit created by Google. It is used to develop cross-platform applications for Android, iOS, Linux, macOS, Windows, Google Fuchsia, and the web from a single codebase.
Key Features
- Cross-Platform: Single codebase for mobile, web, desktop.
- Widgets: Rich set of customizable widgets.
- Hot Reload: See changes instantly without restarting.
- Performance: Compiles to native ARM code.
- Material & Cupertino: Native look on both platforms.
- Dart Language: Optimized for UI development.
- Growing Ecosystem: Many plugins and packages.
Common Use Cases
Cross-Platform Apps
Build for iOS, Android, web, and desktop.
Beautiful UIs
Highly customized user interfaces.
Startup MVPs
Quickly launch products on multiple platforms.
Enterprise Apps
Internal tools with consistent UI across devices.
Example Code
// Flutter main app example
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}
// Navigation example
/*
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondScreen()),
);
*/
// HTTP request example
/*
import 'package:http/http.dart' as http;
Future<void> fetchData() async {
final response = await http.get(Uri.parse('https://api.example.com/data'));
if (response.statusCode == 200) {
print(response.body);
} else {
throw Exception('Failed to load data');
}
}
*/