Skip to content

Instantly share code, notes, and snippets.

@silva-thiago
Last active July 30, 2020 18:03
Show Gist options
  • Save silva-thiago/f518c825eda4e692c31b68103a4e9f27 to your computer and use it in GitHub Desktop.
Save silva-thiago/f518c825eda4e692c31b68103a4e9f27 to your computer and use it in GitHub Desktop.
Set up your environment and start building

Flutter

1. Get started

1.1. Verify your system requirements

To install and run Flutter, your development environment must meet the minimum requirements

1.2. Get the Flutter SDK

  • Select the operating system on which you are installing Flutter
Windows macOS Linux ChromeOS
  • Download the installation bundle to get the latest stable release of the Flutter SDK

  • Extract the file in the desired location

If you don’t want to install a fixed version of the installation bundle, you can get the source code from the Flutter repo on GitHub with the following command:

Windows:

$ git clone https://github.com/flutter/flutter.git -b stable

macOS / Linux / ChromeOS:

$ git clone https://github.com/flutter/flutter.git

You can also change branches or tags as needed. For example, to get just the stable version:

$ git clone https://github.com/flutter/flutter.git -b stable --depth 1

1.3. Add the flutter tool to your path

macOS / Linux / ChromeOS
export PATH="$PATH:`pwd`/flutter/bin"

This command sets your PATH variable for the current terminal window only. To permanently add Flutter to your path, see Update your path

1.4. Update path directly

In some cases, your distribution may not permanently acquire the path when using the above directions. When this occurs, you can change the environment variables file directly. These instructions require administrator privileges:

  • Determine the directory where you placed the Flutter SDK

  • Locate the etc directory at the root of the system, and open the profile file with root privileges

$ sudo nano /etc/profile

Tip: Locate the .bash_profile and if you don't see it, just show the hidden files or you can crete your own to add Flutter to the path

$ touch .bash_profile

You have to close and reopen any existing console windows for these changes to take effect

1.5. Run flutter doctor

Run the following command to see if there are any dependencies you need to install to complete the setup (for verbose output, add the -v flag):

$ flutter doctor

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

1.6. Update your path

To run Flutter commands, take these steps to add Flutter to the PATH environment variable

You can update your PATH variable for the current session at the command line, as shown in Get the Flutter SDK. You’ll probably want to update this variable permanently, so you can run flutter commands in any terminal session.

Windows
If the entry exists, append the full path to `flutter\bin` using `;` as a separator from existing values
If the entry doesn’t exist, create a new user variable named Path with the full path to `flutter\bin` as its value
macOS / Linux / ChromeOS
The steps for modifying this variable permanently for all terminal sessions are machine-specific. Typically you add a line to a file that is executed whenever you open a new window.

For example:

  • Determine the directory where you placed the Flutter SDK. You need this in Step 1.3.
  • Open (or create) the rc file for your shell. For example, Linux uses the Bash shell by default, so edit $HOME/.bashrc. If you are using a different shell, the file path and filename will be different on your machine.
  • Add the following line and change [PATH_TO_FLUTTER_GIT_DIRECTORY] to be the path where you cloned Flutter’s git repo:
$ export PATH="$PATH:[PATH_TO_FLUTTER_GIT_DIRECTORY]/flutter/bin" >> ~/.profile
  • Run source $HOME/.<rc file> to refresh the current window, or open a new terminal window to automatically source the file.
  • Verify that the flutter/bin directory is now in your PATH by running:
$ echo $PATH
  • Verify that the flutter command is available by running
$ which flutter

1.7. Platform setup

iOS setup

macOS supports developing Flutter apps in iOS, Android, and the web (technical preview release). Complete at least one of the platform setup steps now, to be able to build and run your first Flutter app

Xcode (macOS)

  • Install the latest stable version of Xcode (using web download or the Mac App Store)

  • Configure the Xcode command-line tools to use the newly-installed version of Xcode by running the following from the command line:

$ sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
$ sudo xcodebuild -runFirstLaunch
  • Make sure the Xcode license agreement is signed by either opening Xcode once and confirming or running sudo xcodebuild -license from the command line

Set up the iOS simulator (macOS)

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

$ open -a Simulator

Make sure your simulator is using a 64-bit device (iPhone 5s or later) by checking the settings in the simulator’s Hardware > Device menu.

Android setup

Install Android Studio

  • Android Studio offers a complete, integrated IDE experience for Flutter

Set up your Android device

  • To prepare to run and test your Flutter app on an Android device, you need an Android device running Android 4.1 (API level 16) or higher

Set up the Android emulator

2. Set up an editor

Add an editor plugin for Android Studio, IntelliJ, VS Code, or Emacs. If you want to use a different editor, that’s OK

2.1. Install an IDE or an text editor

Intellij IDEA

  • Alternatively, you can also use IntelliJ IDEA Community or Ultimate

Visual Studio Code

VS Code is a lightweight editor with Flutter app execution and debug support

Run Debugger in VS Code

  • You should now be setup to start editing the lib/main.dart file and build your app

2.2. Install the Flutter and Dart plugins

3. Test drive

Select your development tool of choice for writing, building, and running Flutter apps

Create the app

This steps describes how to create a new Flutter app from templates & run it

Use the flutter create command to create a new project:

$ flutter create myapp
$ cd myapp

Run the app

Check that an Android device is running. If none are shown, follow the device-specific instructions on the Install page for your OS

$ flutter devices

Run the app with the following command:

$ flutter run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment