This guide will walk you through creating and running your first Flutter application. You'll set up a new project, build a basic user interface, and run your app on an emulator or physical device.
Before you start, ensure that:
Open Your Terminal or Command Prompt
Depending on your operating system, open the terminal (macOS/Linux) or command prompt (Windows).
Navigate to Your Projects Directory
Change to the directory where you want to create your Flutter project:
cd path/to/your/projects/directory
Create a New Flutter Project
Run the following command to create a new Flutter project:
flutter create my_first_flutter_app
Replace my_first_flutter_app
with your desired project name.
Navigate into the Project Directory
cd my_first_flutter_app
Your new Flutter project will include several important files and directories:
lib/main.dart
: The main entry point of your Flutter application. This file contains the default Flutter application code.pubspec.yaml
: The project’s configuration file where dependencies and project metadata are defined.android/
: Contains Android-specific code and configuration.ios/
: Contains iOS-specific code and configuration.Open the Project in Your IDE
File
-> Open Folder
, then choose the my_first_flutter_app
directory.Open
, and choose the my_first_flutter_app
directory.Launch an Emulator or Connect a Device
AVD Manager
, and start an emulator.Xcode
-> Open Developer Tool
-> Simulator
, and launch a simulator.Run Your App
flutter run
Run
button (▶) or select Run
-> Run 'main.dart'
from the menu.View Your App
Your Flutter app should start running on the selected emulator or physical device. You’ll see a default Flutter demo app with a counter, which you can interact with.
Open lib/main.dart
lib/main.dart
file in your project directory. This file contains the basic code for the default Flutter app.Modify the Code
Change the code in main.dart
to customize the app. For example, you can replace the default content with a simple text widget:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('My First Flutter App'),
),
body: Center(
child: Text('Hello, Flutter!'),
),
),
);
}
}
Hot Reload
With your app running, you can use Flutter’s Hot Reload feature to instantly see changes. Save your main.dart
file, and the app will automatically update with your changes.
Congratulations! You’ve created, built, and run your first Flutter application. You also learned how to modify the default app and use Hot Reload to streamline your development process. Continue exploring Flutter’s widgets and features to build more complex applications.
For more detailed documentation and tutorials, refer to the official Flutter documentation.