Creating a new Flutter project is fundamental to building our first Flutter app. Flutter is a powerful open-source UI framework developed by Google, allowing developers to make beautiful, fast, cross-platform applications.
Before diving into the process, there are a few prerequisites that we'll need to set up:
Install Flutter SDK
Install Android Studio
Download and Install JDK(Java SE Development Kit)
Install a suitable IDE like Android Studio, Visual Studio Code, or any other editor of your preference.
A device or emulator to run your app on.
For detailed installation guide of Flutter, click here.
Once we have mentioned prerequisites in place, we can proceed with creating a new Flutter project using the following steps:
Navigate to the directory where we want to create our Flutter project using the cd
command:
cd /path/to/desired/location
Create a new Flutter project using the following command:
flutter create my_project_name
When creating a Flutter project, use all lowercase letters, separate words with underscores, and only use letters (a-z, A-Z), digits (0-9), and underscores. Using uppercase letters, dashes, or other special symbols in the project name will result in an error stating
... is not a valid Dart package name.
We can now navigate to the project folder and run the project using the following command and make sure we have a device or emulator set up:
cd my_project_name
flutter run
We can pass some optional arguments to the command to customize our project according to the specific requirements.
We can use the --android-language
argument (short: -a
) to choose between Java and Kotlin for Android-specific applications. The default is kotlin
.
flutter create --android-language=java my_project_name
We can use the --ios-language
argument (short: -i
) to choose between Swift and Objective-C for iOS-specific applications. The default is swift
.
flutter create --ios-language=objc my_project_name
By default, Flutter sets up the project for all platforms, such as android
, web
, ios
, windows
, linux
, and macos
. However, we can specify the platforms using the --platforms
argument. Separate multiple values with commas.
flutter create --platforms=ios,web my_project_name
We can specify the project type using the --template
argument (short: -t
), as it would be better if the project is created according to the project type we will work on. Options include app
, module
, package
, and plugin
.
flutter create --template=plugin my_project_name
--platforms
argument will only work if –template
argument will have value app
(default) or plugin
We can provide a code sample for the project using the --sample
argument (short: -s). Pass the sample ID as the argument value.
flutter create --sample=material.TweenAnimationBuilder.1 my_project_name
We can also view all the available samples using the following command:
flutter create --list-samples=list_samples.json
So that's how we can create a new Flutter project using the command line. Flutter allows us to specify the used language for Android and iOS, specify the target platforms, set the project type, and select the code sample.
After successfully creating the project, we can learn about different Flutter packages from the following resources: