1. Installing Flutter
First of all, you need to install Flutter on your system. The process varies slightly depending on your operating system, but you can find detailed instructions on the official Flutter page.
# Per macOS, ad esempio, dopo aver scaricato il pacchetto di Flutter, esegui:
$ tar xf ~/Downloads/flutter_macos_vX.XX-stable.tar.xz
$ export PATH="$PATH:`pwd`/flutter/bin"
# Non dimenticare di eseguire flutter doctor per risolvere eventuali problemi di dipendenza
$ flutter doctor
2. Create a new Flutter project
After installing Flutter, you can create a new project by running the following command in a new directory:
flutter create my_app
cd my_app
3. Flutter Project Structure
The basic structure of a Flutter project is as follows:
my_app/ # radice del progetto
lib/
main.dart # punto di ingresso dell'app
test/
widget_test.dart # test di esempio
.gitignore # elenca i file/directory ignorati da git
.metadata # file di configurazione di Flutter (non modificare)
.packages # file di configurazione di Flutter (non modificare)
.flutter_basic.iml # file di configurazione di Flutter (non modificare)
pubspec.yaml # elenca le dipendenze del progetto
pubspec.lock # versioni esatte delle dipendenze (non modificare)
README.md # documentazione del progetto
4. Developing a Flutter application
The main file of your project is lib/main.dart
. From here your app will start running. A simple code example for a Flutter app is as follows:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Hello World',
home: Scaffold(
appBar: AppBar(
title: Text('Hello World'),
),
body: Center(
child: Text('Hello World!'),
),
),
);
}
}
5. Running the Flutter application
After writing the code, you can run your app on an emulator or physical device by running the following command in the root directory of your project:
flutter run
Conclusion
Done! These are the basic steps to start developing mobile applications with Flutter. Flutter is a very powerful tool that allows you to build native iOS and Android apps from a single code base. Have fun developing apps with Flutter!