Hello readers, today we are going to learn how to install flutter and how to create first project in flutter.
As you all know Now these days’ flutter growing its popularity day by day. Flutter is Google’s cross platform UI development tool kit for mobile, web and for desktop. It uses single code base for every platform.
Let’s get started
Minimum requirements to run a flutter application are:
- Windows 7 SP1 or later (64bit), x86-64 based, recommended windows 10.
- Disk Space 20 GB (including IDE/tools)
- MacOS 64 bit
- Disk space 20 GB including IDE/tools.
- Flutter uses below mentioned command-line tools
- Git 2.x
Requirements to create Flutter project
- Java 11 JDK installed and set in system environment variables.
- Flutter SDK (download from official website http://flutter.dev)
- Android SDK (Install Android Studio recommended)
- Flutter and Dart extension installed.
- Connected Device with laptop for run and test flutter applications.
Install Java 11 JDK
To install java development kit, we need to go on Oracle official website and download jdk 11.
Note: After downloaded Java 11 and set the java jdk path in environment variables, we move to download Flutter SDK
Choose your choice of OS and download zip file and extract it.
Note: please do not install flutter in C:\Program Files because some privileges.
Set Path in User Variables
After extracting flutter, suppose we extract flutter in C:\src\flutter, we need to set the path of flutter bin folder into user environment variables.
Let’s see how to do that
Copy the bin folder path of flutter (C:\src\flutter\bin)
Right click on This PC in window and open Advanced system settings
Click on Environment Variables, below screen will open
Click on new and add path of flutter like below
After setting the path of flutter into env variables we need to test, is flutter installed correctly
For this run from command line “flutter –version” and you will got following output
Great flutter is installed successfully, but wait still there are some few settings are pending to see what is pending we run an another command “flutter doctor” and this command checks your environment and displays a report of the status of your Flutter installation
For example, you will got something like below output
Install Android Studio
Flutter depends on a full installation of Android Studio, so you need to install Android Studio. To install Android Studio, we need to go its official website
Setup Flutter and Dart Plugin in Android Studio
After installing Android Studio, we need to install flutter and dart plugin in android studio.
Steps to install plugins:
- Open Android studio
- Click on File>Settings
- Then choose Plugin in and search for flutter and dart plugin as show in image below:
Verify again is Flutter Setup Completed Correct or something pending
To do so, you need to run again “flutter doctor” and may be it is possible you will get following error:
To remove this error, you only need to run another command of flutter “flutter doctor –android-licenses” and follow the instruction.
If everything is setup correctly then, you will get following out by running “flutter doctor”
No device available. So to run and test flutter application we need to use an Android device running and connected with laptop or desktop.
Set Your Android device
You can use real device or emulator to run and test your apps. You need an Android device running Android 4.1 (API level 16) or higher. We recommend API level 26 or higher.
Connect Real Device
First enable developer options and USB debugging on your device, on android 4.1 and lower, the Developer Options screen is available by default. On Android version 4.2 or higher, you must enable this screen.
To enable developer options, tap the Build Number option 7 times.
Android 8.0.0 (API level 26) and above go to settings> About Phone> Build Number or settings>About Phone> Software Information> Build Number
Now Connect your real device with USB to your laptop.
Now run again “flutter doctor” command and you will see following output:
New Flutter Project in Visual Studio Code
There are a couple ways to create a new flutter project to create a new Flutter project from the Flutter starter app template:
- Open the Command Palette (Ctrl+Shift+P (Cmd+Shift+P on macOS)).
- Select the Flutter: New Projectcommand and press Enter.
- Enter your desired Project name.
- Select a Project location.
Opening a project from existing source code
To open an existing Flutter project:
- Click File > Openfrom the main IDE window.
- Browse to the directory holding your existing Flutter source code files.
- Click Open.
New Project from command line
- Open cmd in window and terminal in macOS
- First run “flutter doctor” command if everything is ok then run.
- “flutter create myfirstproject” use this command to create a new flutter project.
- Now you can open this project in Visual Code Studio, Android Studio.
New Flutter Project in Android Studio
Start the android studio and click on “start a new Flutter project” link as shown in image below:
Choose flutter application as shown in below image:
Now give a name to your project and set the path of your flutter sdk installation as shown in image below:
then click next and give a package name if you want or stay with default as shown in image below:
Click on finish and your default flutter project is ready
Run and Test Flutter Project
To run and test flutter project you can use terminal in android studio and type “flutter run” command this command build your flutter apk and install on your connected real device. In red color tick mark it shows your connected device and a play button to press it you can build you project.
Output of default flutter project
Now connect to Emulator
To know more above how to accelerate your VM, you can read from following links: