Creating Your First Flutter Project
Creating your first Flutter project is the first practical step toward learning Flutter application development. A Flutter project contains the Dart source code, Flutter configuration, platform-specific files, dependencies, assets, tests, and other resources required to build and run an application.
A new Flutter project can be created using VS Code, Android Studio, or the Flutter command-line interface (CLI). The Flutter CLI provides the flutter create command for generating a new project, while VS Code provides the Flutter: New Project command. ([Flutter Documentation](https://docs.flutter.dev/reference/create-new-app))
1. What is a Flutter Project?
A Flutter project is a collection of files and folders that together form a Flutter application.
A typical Flutter project contains:
- Dart source code
- Flutter widgets
- Application configuration
- Package dependencies
- Images and other assets
- Android platform files
- iOS platform files
- Web platform files
- Desktop platform files
- Test files
Flutter uses a single project structure that can target multiple platforms depending on the platforms configured for the project.
2. Requirements Before Creating a Flutter Project
Before creating your first Flutter project, make sure the development environment is configured correctly.
Requirement |
Purpose |
|---|
Flutter SDK |
Provides the Flutter framework and command-line tools. |
Dart SDK |
Provides the Dart programming language used by Flutter. |
VS Code |
Lightweight editor for Flutter development. |
Flutter Extension |
Provides Flutter-specific development features in VS Code. |
Dart Extension |
Provides Dart language support. |
Git |
Used for source-code management and Flutter setup workflows. |
Target Device |
Used to run and test the application. |
3. Verify Flutter Installation
Before creating a project, open a terminal and verify that Flutter is available.
flutter --version
This command displays the installed Flutter version.
Example
Flutter 3.x.x
Dart 3.x.x
The exact version depends on the Flutter SDK installed on the computer.
4. Check the Flutter Development Environment
Use the Flutter Doctor command to check whether the development environment is correctly configured.
flutter doctor
For detailed information, use:
flutter doctor -v
Flutter Doctor can report issues related to Flutter, Android tooling, connected devices, and other parts of the development environment.
Why Use Flutter Doctor?
- Checks Flutter installation
- Checks development tools
- Identifies configuration problems
- Helps troubleshoot missing dependencies
- Checks available development environments
5. Ways to Create a Flutter Project
There are several ways to create a Flutter project.
- Using VS Code
- Using Android Studio
- Using Flutter CLI
For beginners, VS Code and the Flutter CLI are convenient approaches for learning project creation.
6. Creating a Flutter Project Using VS Code
VS Code provides a graphical way to create a Flutter project through the Flutter extension.
Step 1: Open VS Code
Launch Visual Studio Code.
Step 2: Open Command Palette
Go to:
View > Command Palette
Or use:
Ctrl + Shift + P
On macOS:
Cmd + Shift + P
Step 3: Search for Flutter
Type:
Flutter
Step 4: Select Flutter: New Project
Select:
Flutter: New Project
Flutter's official VS Code documentation describes this workflow for creating a new Flutter application. ([Flutter Documentation](https://docs.flutter.dev/reference/create-new-app))
7. Choose the Flutter Project Template
After selecting Flutter: New Project, VS Code asks which Flutter template you want to use.
For your first application, select:
Application
The Application template creates a standard Flutter application that can be used for learning and development.
Other Possible Templates
Depending on the Flutter version and development environment, other project templates may be available for different purposes.
For beginners, the standard Application template is the most appropriate starting point.
8. Select Project Location
VS Code asks you to select the parent directory where the project should be created.
For example:
Documents/
FlutterProjects/
If you select:
FlutterProjects/
and enter the project name:
my_first_app
Flutter creates:
FlutterProjects/
my_first_app/
You normally select the parent folder rather than manually creating the project folder because Flutter creates the project directory itself. ([Flutter Documentation](https://docs.flutter.dev/reference/create-new-app))
9. Choose a Flutter Project Name
Flutter project names should follow the Dart naming convention:
lowercase_with_underscores
Valid Examples
my_first_app
student_app
shopping_app
weather_app
flutter_demo
Invalid or Discouraged Examples
MyFirstApp
my-first-app
my first app
StudentApp
Using lowercase letters with underscores makes the project name consistent with Dart and Flutter naming conventions.
10. Example: Creating my_first_app
Suppose you want to create your first Flutter application.
Use the project name:
my_first_app
The basic process is:
Open VS Code
↓
Command Palette
↓
Flutter: New Project
↓
Application
↓
Select Parent Folder
↓
Enter my_first_app
↓
Flutter Creates Project
↓
Project Opens in VS Code
11. Creating a Flutter Project Using Terminal
You can also create a Flutter project directly from the command line.
The main command is:
flutter create my_first_app
Flutter's official CLI documentation defines flutter create as the command used to create a new Flutter project. ([Flutter CLI Documentation](https://docs.flutter.dev/reference/flutter-cli))
12. Step-by-Step CLI Project Creation
Step 1: Open Terminal
Open Command Prompt, PowerShell, Terminal, or the VS Code integrated terminal.
Step 2: Navigate to the Parent Directory
For example:
cd Documents
You can create a dedicated Flutter projects folder:
mkdir FlutterProjects
Then enter it:
cd FlutterProjects
Step 3: Create the Project
flutter create my_first_app
Step 4: Enter the Project Directory
cd my_first_app
Step 5: Open the Project in VS Code
code .
13. Understanding flutter create
The flutter create command automatically generates the basic files and folders required for a Flutter application.
Example
flutter create student_app
Flutter generates the project structure, platform files, configuration files, and starter application code.
This means you do not need to manually create every folder required for a Flutter application.
14. Create a Minimal Flutter Project
Flutter also supports creating a minimal application using the --empty option.
flutter create --empty my_first_app
This creates a minimal project instead of using the standard starter application template. Flutter's current learning tutorial uses this approach when introducing the fundamentals of a Flutter application. ([Flutter Documentation](https://docs.flutter.dev/learn/pathway/tutorial/create-an-app))
Why Use --empty?
- Creates less starter code
- Useful for learning Flutter fundamentals
- Allows developers to build the UI from scratch
- Useful for tutorials and experiments
15. Flutter Project Structure
After creating a Flutter project, you will see a structure similar to:
my_first_app/
│
├── android/
├── ios/
├── lib/
│ └── main.dart
├── test/
├── web/
├── linux/
├── macos/
├── windows/
├── .gitignore
├── analysis_options.yaml
├── pubspec.yaml
├── README.md
└── pubspec.lock
The exact files and folders can vary depending on the Flutter version and platforms enabled for the project.
16. The lib Folder
The lib folder is one of the most important folders in a Flutter application.
lib/
main.dart
Application Dart code is generally placed inside the lib directory.
Example Future Structure
lib/
├── main.dart
├── screens/
├── widgets/
├── models/
├── services/
└── utils/
As the application becomes larger, developers can organize the code into separate folders and files.
17. The main.dart File
The main.dart file commonly contains the entry point of a Flutter application.
Basic Example
void main() {
runApp(const MyApp());
}
The main() function is the entry point of a Dart program. Flutter's runApp() function starts the Flutter application's widget tree. ([Flutter Documentation](https://docs.flutter.dev/learn/pathway/tutorial/create-an-app))
18. Understanding runApp()
The runApp() function takes a widget and makes it the root of the Flutter application's widget tree.
Example
void main() {
runApp(
const MyApp(),
);
}
Here, MyApp becomes the root widget.
19. Create Your First Flutter UI
Let's create a simple Flutter application that displays a welcome message.
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(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: const Text('My First Flutter App'),
),
body: const Center(
child: Text(
'Hello Flutter!',
style: TextStyle(
fontSize: 24,
),
),
),
),
);
}
}
20. Explanation of the First Flutter Program
Import Material Library
import 'package:flutter/material.dart';
This imports Flutter's Material Design widgets and related functionality.
main() Function
void main() {
runApp(const MyApp());
}
This starts the Flutter application.
MyApp Class
class MyApp extends StatelessWidget
MyApp is a widget that represents the root of the application.
build() Method
@override
Widget build(BuildContext context)
The build() method describes the widget tree that should be displayed.
MaterialApp
MaterialApp(
...
)
MaterialApp provides the basic application structure and Material Design behavior.
Scaffold
Scaffold(
appBar: AppBar(...),
body: ...
)
Scaffold provides a standard screen structure.
AppBar
AppBar(
title: const Text('My First Flutter App'),
)
The AppBar displays a toolbar at the top of the screen.
Center
Center(
child: Text('Hello Flutter!'),
)
The Center widget positions its child in the center of the available space.
Text
Text('Hello Flutter!')
The Text widget displays text on the screen.
21. Understanding the Widget Tree
Flutter interfaces are constructed using widgets. Widgets are arranged in a hierarchical structure called the widget tree.
Example Widget Tree
MaterialApp
|
└── Scaffold
|
├── AppBar
| └── Text
|
└── Center
└── Text
This widget-based architecture is one of the fundamental concepts of Flutter development.
22. Running Your First Flutter Project
After creating the project, you need a target device to run the application.
Possible targets include:
- Android Emulator
- Physical Android device
- Chrome
- Windows
- macOS
- Linux
- iOS Simulator on macOS
23. Check Available Devices
Use:
flutter devices
This command lists the devices detected by Flutter.
Example
2 connected devices:
Chrome
Android Emulator
The actual output depends on the devices configured on your computer.
24. Run the Application Using VS Code
Open the Flutter project in VS Code.
Select the target device from the device selector in the VS Code status bar.
Then press:
F5
Alternatively, use:
Run > Start Debugging
VS Code's Flutter integration supports creating, running, and debugging Flutter projects. ([Flutter Documentation](https://docs.flutter.dev/tools/vs-code))
25. Run the Application Using Terminal
Open the terminal inside the project directory.
flutter run
Flutter will build the application and run it on an available target.
Run on Chrome
flutter run -d chrome
The Flutter tutorial demonstrates running a newly created Flutter application on Chrome using this command. ([Flutter Documentation](https://docs.flutter.dev/learn/pathway/tutorial/create-an-app))
26. Run on a Specific Device
First, check the available devices:
flutter devices
Then specify a device ID:
flutter run -d <device_id>
Example
flutter run -d chrome
The exact device ID depends on your environment.
27. Hot Reload
Hot Reload allows developers to quickly see many changes made to Flutter code while the application is running.
Example
Initially:
Text('Hello Flutter!')
Change it to:
Text('Welcome to My App!')
Save the file and perform Hot Reload.
The updated text can appear without completely restarting the application. Flutter's tutorial demonstrates using Hot Reload to update the running application. ([Flutter Documentation](https://docs.flutter.dev/learn/pathway/tutorial/create-an-app))
28. Hot Reload vs Hot Restart
Feature |
Hot Reload |
Hot Restart |
|---|
Purpose |
Apply code changes quickly |
Restart the Flutter application |
Speed |
Very fast in typical development |
Slower than Hot Reload |
State |
Generally preserves current state |
Resets application state |
Usage |
UI and logic changes |
When a full restart is required |
29. The pubspec.yaml File
The pubspec.yaml file is an important configuration file located in the root of the Flutter project.
Example
name: my_first_app
description: A new Flutter application.
environment:
sdk: ^3.0.0
dependencies:
flutter:
sdk: flutter
dev_dependencies:
flutter_test:
sdk: flutter
The exact generated content depends on the Flutter and Dart versions and project configuration.
A new Flutter project includes a basic pubspec file containing project metadata and dependencies. ([Flutter Documentation](https://docs.flutter.dev/tools/pubspec))
30. What is the Purpose of pubspec.yaml?
The pubspec.yaml file can contain information about:
- Project name
- Project description
- SDK constraints
- Dependencies
- Development dependencies
- Assets
- Fonts
- Flutter-specific configuration
31. Adding a Package to Your Project
Flutter applications can use external packages.
Example
To add the http package using the Flutter CLI:
flutter pub add http
This updates the project's dependency configuration.
Get Dependencies
flutter pub get
The flutter pub get command resolves and downloads the packages specified by the project.
32. Understanding pubspec.lock
The pubspec.lock file records the specific versions of resolved packages used by a project.
It helps maintain consistent dependency versions between builds. Flutter documentation notes that this file is generated when dependencies are resolved during the project's first build or package resolution process. ([Flutter Documentation](https://docs.flutter.dev/tools/pubspec))
33. Understanding the Android Folder
android/
The android folder contains Android-specific project files.
It becomes important when configuring or building the Flutter application for Android.
Examples of Android-related configuration include:
- Android application configuration
- Gradle configuration
- Android permissions
- Android-specific resources
- Native Android integration
34. Understanding the iOS Folder
ios/
The ios folder contains iOS-specific project files.
It is used when building the Flutter application for iOS.
iOS development requires macOS and Apple's development tooling.
35. Understanding the Web Folder
web/
The web folder contains web-specific files used when Flutter Web support is enabled for the project.
You can run a Flutter web application using:
flutter run -d chrome
Flutter also supports adding web support to an existing project using the appropriate Flutter tooling. ([Flutter Documentation](https://docs.flutter.dev/platform-integration/web/building))
36. Understanding the Test Folder
test/
The test folder is used for automated tests.
Example
test/
widget_test.dart
Flutter projects can contain unit tests, widget tests, and other types of automated tests.
37. Understanding the README.md File
The README.md file generally contains documentation about the project.
It can include:
- Project description
- Installation instructions
- Usage instructions
- Features
- Development information
- Contribution guidelines
38. Understanding .gitignore
The .gitignore file specifies files and folders that Git should generally not track.
This is useful when storing Flutter projects in Git repositories.
Example Concept
build/
.dart_tool/
*.log
The exact generated .gitignore content depends on the Flutter project and platform configuration.
39. Project Root Directory
The project root is the main directory of the Flutter project.
For example:
my_first_app/
├── lib/
├── android/
├── ios/
├── test/
├── pubspec.yaml
└── README.md
The root directory is important because files such as pubspec.yaml are located there.
When using VS Code with Flutter DevTools, the project root should be opened so that VS Code can recognize the Flutter project correctly. ([Flutter Documentation](https://docs.flutter.dev/tools/devtools/vscode))
40. Creating a Project with a Specific Organization
When creating applications intended for future distribution, project organization information can be configured according to the application's requirements.
For example, an organization might use a domain such as:
com.example
Organization and project configuration can vary depending on the platform and application requirements.
41. Creating a Flutter Project with CLI Options
The Flutter CLI supports different options for project creation.
View Available Options
flutter create --help
This displays available options for the flutter create command.
Basic Project
flutter create my_app
Minimal Project
flutter create --empty my_app
Flutter's current CLI documentation provides the create command and its available options. ([Flutter Documentation](https://docs.flutter.dev/reference/flutter-cli))
42. Practical Example: Student App
Let's create a simple Flutter application called:
student_app
Step 1: Create Project
flutter create student_app
Step 2: Enter Directory
cd student_app
Step 3: Open VS Code
code .
Step 4: Open main.dart
lib/main.dart
Step 5: Add Code
import 'package:flutter/material.dart';
void main() {
runApp(const StudentApp());
}
class StudentApp extends StatelessWidget {
const StudentApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: const Text('Student App'),
),
body: const Center(
child: Text(
'Welcome to Student App',
style: TextStyle(
fontSize: 26,
fontWeight: FontWeight.bold,
),
),
),
),
);
}
}
Step 6: Run the App
flutter run
43. Practical Example: Simple Counter App
A counter application is a useful beginner project because it demonstrates widgets, state, events, and UI updates.
import 'package:flutter/material.dart';
void main() {
runApp(const CounterApp());
}
class CounterApp extends StatelessWidget {
const CounterApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: const CounterPage(),
);
}
}
class CounterPage extends StatefulWidget {
const CounterPage({super.key});
@override
State<CounterPage> createState() => _CounterPageState();
}
class _CounterPageState extends State<CounterPage> {
int count = 0;
void incrementCounter() {
setState(() {
count++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Counter App'),
),
body: Center(
child: Text(
'Count: $count',
style: const TextStyle(
fontSize: 30,
),
),
),
floatingActionButton: FloatingActionButton(
onPressed: incrementCounter,
child: const Icon(Icons.add),
),
);
}
}
44. Explanation of Counter Example
StatefulWidget
class CounterPage extends StatefulWidget
A StatefulWidget is useful when the UI needs to change during the lifetime of the application.
State Variable
int count = 0;
This variable stores the current counter value.
setState()
setState(() {
count++;
});
setState() tells Flutter that the state has changed and that the relevant UI should be rebuilt.
FloatingActionButton
FloatingActionButton(
onPressed: incrementCounter,
child: const Icon(Icons.add),
)
The button calls the incrementCounter() function when pressed.
45. Debugging Your First Flutter Project
VS Code provides debugging functionality for Flutter applications.
Start Debugging
F5
Or:
Run > Start Debugging
Debugging Features
- Breakpoints
- Step Over
- Step Into
- Step Out
- Continue execution
- Variable inspection
- Call stack
- Debug Console
- Flutter DevTools
46. Flutter Inspector
The Flutter Inspector helps developers inspect the widget tree of a running Flutter application.
Example Widget Tree
MaterialApp
|
└── Scaffold
|
├── AppBar
| └── Text
|
└── Center
└── Text
This makes it easier to understand how widgets are arranged in the application.
47. Flutter DevTools
Flutter DevTools provides tools for inspecting and debugging Flutter applications.
DevTools Can Help With
- Widget inspection
- Layout debugging
- Performance analysis
- Memory analysis
- Network inspection
- Logging
To use DevTools from VS Code, open the Flutter project root, start a debug session, and then use the available Open DevTools commands. ([Flutter Documentation](https://docs.flutter.dev/tools/devtools/vscode))
48. Common Errors When Creating a Flutter Project
Error 1: flutter is not recognized
flutter is not recognized as an internal or external command
Solution: Verify that Flutter is installed and that the Flutter SDK's bin directory is available in PATH.
Error 2: No devices found
No supported devices connected
Solution: Start an emulator, connect a physical device, or use a supported web/desktop target.
Error 3: Project name is invalid
Solution: Use lowercase letters and underscores.
my_first_app
Error 4: Dependencies are not available
Solution:
flutter pub get
Error 5: Flutter Doctor reports configuration problems
Solution:
flutter doctor -v
Read the reported diagnostic messages and complete the missing configuration.
49. Useful Flutter Commands
Command |
Purpose |
|---|
flutter --version |
Displays Flutter version. |
flutter doctor |
Checks Flutter environment. |
flutter doctor -v |
Displays detailed diagnostic information. |
flutter create app_name |
Creates a Flutter project. |
flutter create --empty app_name |
Creates a minimal Flutter project. |
flutter devices |
Lists available devices. |
flutter run |
Runs the Flutter application. |
flutter run -d chrome |
Runs the application on Chrome. |
flutter pub get |
Gets project dependencies. |
flutter pub add package_name |
Adds a package to the project. |
flutter analyze |
Analyzes project code. |
flutter clean |
Removes generated build files. |
flutter create --help |
Displays project creation options. |
50. Complete First Project Workflow
Install Flutter
↓
Install VS Code
↓
Install Flutter & Dart Extensions
↓
Run flutter doctor
↓
Open VS Code
↓
Flutter: New Project
↓
Select Application
↓
Select Parent Folder
↓
Enter Project Name
↓
Project Generated
↓
Open lib/main.dart
↓
Write Flutter Code
↓
Select Device
↓
Run Application
↓
Use Hot Reload
↓
Debug Application
↓
Use Flutter Inspector
↓
Use DevTools
51. Project Creation Checklist
- Flutter SDK is installed.
- VS Code is installed.
- Flutter extension is installed.
- Dart extension is installed.
- Flutter Doctor has been checked.
- A valid project name has been selected.
- The project has been generated successfully.
pubspec.yaml exists in the project root.
lib/main.dart exists.
- A target device is available.
- The application runs successfully.
- Hot Reload works.
- Debugging works.
52. Interview Questions
Q1. What is a Flutter project?
A Flutter project is a collection of Dart source code, configuration files, dependencies, assets, tests, and platform-specific files used to build a Flutter application.
Q2. Which command creates a Flutter project?
flutter create project_name
Q3. How do you create a Flutter project in VS Code?
Open the Command Palette, select Flutter: New Project, select the Application template, choose the parent directory, and enter a valid project name.
Q4. What naming convention should be used for Flutter project names?
Flutter project names should normally use the lowercase_with_underscores convention.
Q5. What is the purpose of main.dart?
main.dart commonly contains the main() function and the starting widget of the Flutter application.
Q6. What is pubspec.yaml?
pubspec.yaml is the project's configuration file that contains metadata, dependencies, assets, and other project settings.
Q7. What is flutter pub get?
flutter pub get resolves and retrieves the project's declared dependencies.
Q8. What is flutter run?
flutter run builds and runs a Flutter application on a selected or available target device.
Q9. What is Hot Reload?
Hot Reload allows many changes to Flutter code to be reflected quickly in a running application while generally preserving its current state.
Q10. What is the widget tree?
The widget tree is the hierarchical structure formed by Flutter widgets that describes the application's user interface.
53. JustAcademy Flutter Training
For structured Flutter learning and practical application development, explore the JustAcademy Flutter Training course:
JustAcademy Flutter Training
To register for a Flutter course demo:
Register for Flutter Course Demo
54. Key Points to Remember
- A Flutter project contains Dart code, configuration, dependencies, assets, tests, and platform-specific files.
- The
flutter create command creates a new Flutter project.
- VS Code provides the Flutter: New Project command for project creation.
- Flutter project names normally use lowercase letters and underscores.
- The
lib directory contains the main Dart application code.
lib/main.dart commonly contains the application entry point.
pubspec.yaml manages project metadata and dependencies.
flutter pub get retrieves project dependencies.
flutter devices lists available devices.
flutter run runs the application.
flutter run -d chrome can run a Flutter web application on Chrome.
- Hot Reload speeds up the development process.
- Flutter Inspector helps inspect the widget tree.
- DevTools provides debugging and performance-analysis tools.
55. Conclusion
Creating your first Flutter project is an important milestone in learning Flutter development. The process begins by verifying the Flutter environment, creating a project using VS Code or the Flutter CLI, understanding the generated project structure, editing main.dart, selecting a target device, and running the application.
The basic project creation process can be summarized as:
flutter create my_first_app
↓
cd my_first_app
↓
code .
↓
Open lib/main.dart
↓
Write Flutter Code
↓
Select Device
↓
flutter run
↓
Hot Reload
↓
Debug and Test
Once you understand this workflow, you can move on to building screens, working with widgets, handling user input, managing state, using packages, connecting APIs, and developing complete Flutter applications.