Flutter & Android Studio – Brain Mentors Skip to content

Flutter & Android Studio

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

Hardware Requirements

Minimum requirements to run a flutter application are:

For Window

  1. Windows 7 SP1 or later (64bit), x86-64 based, recommended windows 10.
  2. Disk Space 20 GB (including IDE/tools)

For MacOS

  1. MacOS 64 bit
  2. Disk space 20 GB including IDE/tools.
  3. Flutter uses below mentioned command-line tools
    1.  Bash
    2. Curl
    3. Git 2.x
    4. Mkdir
    5. Rm
    6. Unzip
    7. Which

Requirements to create Flutter project

  1. Java 11 JDK installed and set in system environment variables.
  2. Flutter SDK (download from official website http://flutter.dev)
  3. Android SDK (Install Android Studio recommended)
  4. Flutter and Dart extension installed.
  5. 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

Download Flutter

To download flutter, we go to flutter official website

 https://flutter.dev/docs/get-started/install

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

https://developer.android.com/studio

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:

  1. Open Android studio
  2. Click on File>Settings
  3. 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:

  1. Open the Command Palette (Ctrl+Shift+P (Cmd+Shift+P on macOS)).
  2. Select the Flutter: New Projectcommand and press Enter.
  3. Enter your desired Project name.
  4. Select a Project location.

Opening a project from existing source code

To open an existing Flutter project:

  1. Click File > Openfrom the main IDE window.
  2. Browse to the directory holding your existing Flutter source code files.
  3. Click Open.

New Project from command line

  1. Open cmd in window and terminal in macOS
  2. First run “flutter doctor” command if everything is ok then run.
  3. “flutter create myfirstproject” use this command to create a new flutter project.
  4. 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

Warning: Emulator uses your laptop or desktop resources, result slow down your system and also Android emulator is runs too slowly if hardware acceleration is not available computer that runs it. If you want to run and test on Android Emulator, you can follow these steps:

To know more above how to accelerate your VM, you can read from following links:

 

https://developer.android.com/studio/run/emulator-acceleration

https://docs.microsoft.com/en-us/xamarin/android/get-started/installation/android-emulator/hardware-acceleration?pivots=windows

Sign Up and Start Learning