Newby Coder header banner

Running a Flutter App


Running an Android app in Flutter requires Android SDK and an emulator or a connected Android device and running an iOS App requires Xcode and a simulator or a connected iOS device

Use following command to check if required dependencies are installed

flutter doctor

This command checks environment and displays a report to the terminal window

If flutter is not installed check Installing Flutter

Running in Linux/Ubuntu

Flutter requires Android Sdk

Check Installation in Linux

Use Java 8 instead of Java 14, which might lead to gradle issues

Switching Java

Install java 8 (if not already) with

sudo apt-get install openjdk-8-jdk openjdk-8-jre

Check there's other version(s) of java installed

 update-java-alternatives -l

Switch to java 8 using its path (or name)

sudo update-java-alternatives -s /usr/lib/jvm/java-1.8.0-openjdk-amd64

Check version

java -version

Create app

If not created already, create app using flutter command

flutter create nc_app

where nc_app is name of the application

By convention, Flutter apps and packages are named in lower case and words are separated by underscore (_)

Change current working directory (here nc_app)

cd nc_app

Set up Android device

Skip this step to set up an emulator instead

An Android device running Android 4.1 (API level 16) or higher is required to run Flutter application

Starting emulator

This step can be skipped if a real device is connected

Emulator can be started using emulator command or using Android Studio

For systems with low memory, use emulator command to avoid waiting for applications to open up or (probably) freezing the system

To use emulator command, a device has to be created first using Android Studio → Avd Manager

Creating emulator using Android Studio

Open Avd Manager using Configuration dropdown when Android Studio is started or

Android Studio → Tools → AVD Manager

or Android Studio → Tools → Android → AVD Manager

cl-linux-astudio-open-avd-manager

Create Virtual Device

cl-linux-astudio-avd-create

Select Pixel 2 and press Next

Download an image shown under Recommended Tab

cl-linux-astudio-avd-image-download

Select an Image

Click Next and Select Advanced Settings

Select Hardware Gles

cl-linux-astudio-avd-settings

Click Finish and then start the device

Start emulator using cli

Open Terminal and enter

emulator -list-avds

If it doesn't show a device, create a Virtual Device by following above steps

Start emulator using emulator -avd <Device Name> command

emulator -avd Pixel_2_API_28

Running the app

Use following command to run a Flutter application

flutter run

Modifying an app

Open lib/main.dart in a text editor and edit some lines

Press r on terminal to Hot reload

Press Shift + r for hot restart

Re run flutter run command when editing pubspec.yaml or adding, removing files used in application, in case

Run issues

Check Flutter run issues

Running Flutter iOS application in MacOS

Start an iOS simulator

To prepare to run and test Flutter app on iOS simulator, follow these steps:

To check connected devices, run

flutter devices

Create app

If not created already, create app using flutter command

flutter create nc_app

where nc_app is name of the application

By convention, Flutter apps and packages are named in lower case and words are separated by underscore (_)

Change current working directory (here nc_app)

cd nc_app

Run app

Use flutter run command to run flutter application

flutter run

This command internally runs flutter pub get and pod install to install required dependencies and runs the application on a connected device

Open application in Xcode

Open Xcode

Navigate to File → Open

Navigate to and select (flutter project directory) → ios → Runner.xcodeproj and click Open