Getting Started with Flutter: Installation and Setup

Learn how to install Flutter, set up your development environment, and create your first app with this comprehensive guide.

In the world of cross-platform mobile app development, Flutter stands out as one of the most versatile and powerful frameworks available. Developed by Google, Flutter allows developers to build high-quality, natively compiled applications for mobile, web, and desktop from a single codebase. It is an open-source framework that combines a fast development cycle with a rich set of pre-designed widgets, giving developers a highly customizable experience.

Before diving into installation and setup, it’s important to understand what makes Flutter unique. Unlike other frameworks such as React Native or Xamarin, Flutter doesn’t rely on WebViews or device OEM widgets. Instead, it uses its own high-performance rendering engine to create visuals. This engine, called Skia, ensures that your apps not only look good but also run smoothly across platforms. Flutter’s architecture allows developers to create apps with a truly consistent look and feel, regardless of the device.

Another reason for Flutter’s growing popularity is the Dart programming language. Flutter uses Dart, a language also created by Google, that offers features such as ahead-of-time (AOT) and just-in-time (JIT) compilation, enabling fast app execution and a highly productive development environment. Dart is easy to learn, especially if you are familiar with other object-oriented languages such as Java, JavaScript, or C#. With Flutter’s hot reload feature, developers can see changes instantly without restarting the app, significantly speeding up the iteration process.

In this guide, we’ll cover how to get started with Flutter, focusing on installation and setup. Whether you’re developing for iOS, Android, or the web, the process to get Flutter up and running is straightforward. By the end of this guide, you’ll have a solid foundation and be ready to create your first Flutter project.

Installing Flutter

The first step in starting your Flutter journey is installing the Flutter SDK. The SDK contains all the tools necessary to build, test, and deploy Flutter apps across multiple platforms. Let’s walk through the installation process on the three major operating systems: Windows, macOS, and Linux.

Step 1: Installing Flutter on Windows

  1. System Requirements:
    • Operating System: Windows 10 or later (64-bit).
    • Disk Space: 1.64 GB (does not include disk space for IDE/tools).
    • Tools: Git for Windows. If Git is not already installed, you can download it from the official Git website.
  2. Download the Flutter SDK:
    • Visit the official Flutter website and download the Flutter SDK for Windows.
    • Once downloaded, extract the ZIP file to a suitable location, such as C:\src\flutter (do not place Flutter in a directory that requires elevated privileges like C:\Program Files).
  3. Update the System Path:
    • You need to add Flutter to your system’s PATH. This will allow you to run Flutter commands globally from any terminal window.
    • Open File Explorer, right-click This PC, and select Properties. Choose Advanced system settings and click Environment Variables.
    • In the User variables section, select the Path variable and click Edit. Add the path to your Flutter bin folder, which should be something like C:\src\flutter\bin.
  4. Verify the Installation:
    • Open a new command prompt window and type flutter doctor. This will check your system for any missing dependencies and display information about your Flutter installation.
  5. Install Android Studio:
    • Although you can develop Flutter apps in multiple IDEs, Android Studio is one of the most commonly used tools, especially for Android development. Download and install Android Studio, then follow the setup wizard to install Android SDK and additional tools like Android Virtual Device (AVD).
    • After installation, ensure Android Studio is correctly configured by running flutter doctor again.

Step 2: Installing Flutter on macOS

  1. System Requirements:
    • Operating System: macOS 10.14 or later.
    • Tools: Git (installed by default in macOS), Xcode (required for iOS development).
  2. Download the Flutter SDK:
    • Head to the Flutter download page and download the latest Flutter SDK for macOS.
    • Extract the file to a convenient directory, such as ~/development/flutter.
  3. Update the PATH Variable:
    • To enable Flutter commands from any terminal window, you must update your PATH. Open your terminal and run:
export PATH="$PATH:`pwd`/flutter/bin"
  • To make this change permanent, add the above line to your bashrc or zshrc file, depending on your shell.
  1. Verify the Installation:
    • In the terminal, run flutter doctor to check for any missing dependencies. On macOS, you’ll likely be prompted to install Xcode, as it’s required for iOS development.
    • Follow the instructions to install Xcode from the App Store.
  2. Install Android Studio (Optional):
    • If you plan on developing for Android as well, install Android Studio, similar to the steps listed for Windows.

Step 3: Installing Flutter on Linux

  1. System Requirements:
    • Operating System: Any modern 64-bit Linux distribution.
    • Tools: Git, bash, curl, unzip.
  2. Download the Flutter SDK:
    • Visit the official Flutter installation page and download the latest version of Flutter for Linux.
    • Extract the contents to your home directory or another convenient location, for example, ~/development/flutter.
  3. Update the PATH Variable:
    • Just like with Windows and macOS, you need to add Flutter to your system’s PATH. Run the following in the terminal:
export PATH="$PATH:`pwd`/flutter/bin"
  • To make the change persistent, add the above line to your bashrc or zshrc file.

Verify the Installation:

  • Open a terminal and run flutter doctor to check for missing dependencies.

Install Android Studio:

Configuring Your Development Environment

Once you’ve installed the Flutter SDK on your machine, the next step involves configuring your development environment to ensure a smooth workflow. This includes setting up your Integrated Development Environment (IDE), installing necessary plugins, and configuring simulators or emulators for testing your app on both iOS and Android devices.

Step 1: Setting Up Your IDE

While you can use any text editor to develop Flutter apps, using an IDE with Flutter support can significantly improve your development experience. The two most popular IDEs for Flutter development are Visual Studio Code and Android Studio. Let’s explore how to set up both of these environments for Flutter.

Visual Studio Code (VS Code)

Visual Studio Code is a lightweight code editor that is popular for its speed and simplicity. Here’s how you can set up VS Code for Flutter development:

  1. Install Visual Studio Code:
  2. Install the Flutter Extension:
    • After installation, open VS Code and navigate to the Extensions marketplace by clicking on the square icon in the left sidebar.
    • Search for Flutter and install the official Flutter extension. This will automatically install the Dart extension, which is required to write Dart code for Flutter.
  3. Configuring the Dart and Flutter Plugins:
    • Once the Flutter extension is installed, VS Code will offer a range of features such as syntax highlighting, IntelliSense, and debugging support.
    • You can now open any Flutter project or create a new one directly from VS Code by pressing Ctrl+Shift+P and typing Flutter: New Project.
  4. Enable the Flutter SDK Path:
    • Open the Command Palette (Ctrl+Shift+P), search for Flutter: Select SDK Path, and set the path to your Flutter SDK directory. For example, on Windows, it might be C:\src\flutter, and on macOS or Linux, it might be ~/development/flutter.
  5. Test Your Setup:
    • To verify that everything is working correctly, open the terminal in VS Code and run flutter doctor. This should show that your Flutter setup is complete, with VS Code recognized as the development IDE.

Android Studio

If you plan to work extensively with Android, Android Studio might be a better option as it provides more in-depth Android-specific tools like virtual devices and performance profiling. Here’s how you can configure Android Studio for Flutter development:

  1. Install Android Studio:
    • Download and install Android Studio from the official website.
    • During installation, ensure that the Android SDK and Android Virtual Device (AVD) are selected as additional components.
  2. Install the Flutter Plugin:
    • After installing Android Studio, launch it and open the Plugins menu from the Preferences (on macOS) or File -> Settings (on Windows/Linux).
    • Search for Flutter in the plugins marketplace, install it, and restart Android Studio.
    • The Dart plugin will automatically be installed along with the Flutter plugin.
  3. Create a New Flutter Project:
    • You can now create a new Flutter project directly from Android Studio by going to File -> New -> New Flutter Project.
    • Android Studio offers rich support for Flutter, including project templates, debugging tools, and performance monitoring.
  4. Configure Virtual Devices (AVD):
    • Android Studio comes with a built-in Android Virtual Device (AVD) manager, which allows you to emulate different Android devices. To set this up, go to Tools -> AVD Manager, and create a virtual device with the specifications of your choice.
    • Ensure the virtual device runs on an x86 system image for better performance when testing Flutter apps.

Step 2: Configuring Simulators and Emulators

Testing your Flutter apps on real devices or emulators is essential to ensure they function as expected on different platforms. Flutter supports both Android emulators and iOS simulators for development. Here’s how to configure each:

Android Emulator

  1. Create an Android Emulator:
    • After setting up Android Studio, you can use the AVD Manager to create a virtual device for testing. To do this, open Android Studio, navigate to Tools -> AVD Manager, and click on Create Virtual Device.
    • Choose a device model and select a system image. For optimal performance, it’s recommended to choose an x86-based system image.
    • Once created, launch the emulator by selecting the virtual device and clicking Play in the AVD Manager.
  2. Connect to Flutter:
    • Once the emulator is running, you can connect it to Flutter by running the flutter devices command in the terminal. You should see your emulator listed among available devices.
    • You can now run your app on the emulator using flutter run.

iOS Simulator (macOS Only)

  1. Install Xcode:
    • To test your app on iOS, you need to install Xcode from the Mac App Store.
    • After installation, open Xcode, and navigate to Preferences -> Components. Here, you can download and manage various versions of the iOS simulators.
  2. Launch the iOS Simulator:
    • Open Xcode and navigate to Xcode -> Open Developer Tools -> Simulator. This will launch the iOS simulator, where you can test your Flutter app on a variety of virtual iPhones.
  3. Connect to Flutter:
    • Similar to Android, you can connect the iOS simulator to Flutter by running flutter devices in the terminal. The iOS simulator should be listed as an available device.
    • Use flutter run to deploy your Flutter app to the iOS simulator for testing.

Step 3: Configuring Real Devices

While emulators and simulators are great for initial testing, it’s also important to test your app on real devices to ensure optimal performance and compatibility. Here’s how you can configure both Android and iOS devices for testing:

Android Device

  1. Enable Developer Mode:
    • On your Android device, go to Settings -> About Phone, and tap on the Build Number seven times to enable Developer Options.
  2. Enable USB Debugging:
    • Once Developer Mode is enabled, navigate to Settings -> Developer Options and enable USB Debugging. This will allow you to run and debug apps from your computer.
  3. Connect Your Device:
    • Connect your Android device to your computer using a USB cable. Run the flutter devices command in the terminal, and you should see your device listed.
    • You can now run your Flutter app on your Android device using the flutter run command.

iOS Device (macOS Only)

  1. Install Xcode and Connect Your Device:
    • Similar to testing on the iOS simulator, you’ll need to have Xcode installed.
    • Connect your iOS device to your Mac via USB.
  2. Trust Your Device:
    • On your iPhone or iPad, you will receive a prompt asking whether to trust the connected computer. Ensure that you trust the device.
  3. Deploy to Your Device:
    • Once connected, run flutter devices to ensure that your iOS device is recognized.
    • Use flutter run to deploy your app to the iPhone or iPad for real-world testing.

Creating Your First Flutter App

Now that you’ve installed Flutter, configured your IDE, and set up emulators or real devices, it’s time to create your first Flutter app. In this section, we’ll walk you through the process of generating a new Flutter project, understanding the basic structure, and running the app on both an emulator and a real device. This hands-on experience will provide you with a foundational understanding of how Flutter works and give you the tools you need to start building more complex applications.

Step 1: Creating a New Flutter Project

The first step in building a Flutter app is to create a new project. Whether you’re using VS Code or Android Studio, the process is relatively similar.

Using Visual Studio Code

  1. Open VS Code and press Ctrl+Shift+P to bring up the Command Palette.
  2. In the Command Palette, type Flutter: New Project and press Enter.
  3. Choose the Application option. VS Code will prompt you to provide a name for your new project. Type a name (e.g., my_first_flutter_app) and press Enter.
  4. You’ll be asked to select a location to save your project. Choose your desired directory.
  5. Once the project is created, VS Code will automatically open the project folder with all the necessary files and directories.

Using Android Studio

  1. Open Android Studio and go to File -> New -> New Flutter Project.
  2. In the dialog box that appears, select Flutter Application and click Next.
  3. Provide a project name (e.g., my_first_flutter_app), choose your Flutter SDK path (if not automatically populated), and specify the project location on your computer.
  4. Choose a description for your project, and ensure the Platform Channels options (Android, iOS) are selected based on your target platforms.
  5. Click Finish to create the project.

Once you’ve created the project, you’ll see a standard Flutter directory structure, which we’ll explore next.

Step 2: Understanding the Flutter Project Structure

When you create a new Flutter project, the framework automatically generates several files and directories. Understanding the purpose of each will help you organize your app as it grows in complexity.

Here’s a breakdown of the main components in a typical Flutter project:

  • lib: This is the most important folder in your Flutter project. It contains the Dart code that makes up your app. By default, it includes a single file: main.dart. This file is the entry point of your Flutter app, where the app starts executing.
  • android: This directory holds the native Android code required to build the app. If you need to customize platform-specific behavior or add Android-specific libraries, you’ll modify files within this folder.
  • ios: Similar to the android folder, this contains the native code for the iOS version of your app. For example, if you need to integrate native iOS features or libraries, you would do it here.
  • test: This folder contains unit tests for your Flutter application. Testing is an important part of any app development process, and Flutter makes it easy to write tests for both logic and UI.
  • pubspec.yaml: This is the configuration file where you define your app’s dependencies, assets, fonts, and other metadata. If you want to add a package or library from the Flutter ecosystem, you’ll specify it in this file.
  • build: This folder is automatically generated by Flutter and contains the compiled code for your app. You generally don’t need to interact with this folder directly.

Understanding this structure helps you navigate and organize your Flutter project efficiently, especially as your app grows larger.

Step 3: Running the App on an Emulator or Device

Now that your first Flutter project is set up, it’s time to run the app and see it in action. Flutter’s default project template includes a basic app with a counter button that increments when pressed. Running this app will confirm that everything is working correctly in your environment.

Running on an Android Emulator

  1. Start the Emulator: Open Android Studio, go to Tools -> AVD Manager, and click Launch next to the Android Virtual Device you created earlier. Wait for the emulator to boot up.
  2. Run the App: In VS Code, open the terminal by selecting Terminal -> New Terminal. In Android Studio, use the built-in terminal at the bottom of the window.
  3. Run the Command: In the terminal, type flutter run and press Enter. Flutter will detect the running emulator and build the app for it.
  4. View the App: Once the build completes, you’ll see your app running on the emulator. The app displays a simple screen with a floating action button. Tap the button to increment the counter and see how Flutter’s UI responds in real-time.

Running on an iOS Simulator (macOS only)

  1. Launch the iOS Simulator: Open Xcode and go to Xcode -> Open Developer Tool -> Simulator. Choose the type of iPhone you want to emulate.
  2. Run the App: In the terminal, type flutter run. Flutter will detect the iOS simulator and build the app for it.
  3. View the App: After the build is complete, you’ll see the app running in the iOS simulator, behaving similarly to how it runs on Android.

Running on a Real Android Device

  1. Connect Your Device: Plug in your Android device via USB. Ensure USB Debugging is enabled in the Developer Options.
  2. Detect the Device: In the terminal, run flutter devices. You should see your device listed.
  3. Run the App: Type flutter run to build the app and deploy it to your device.
  4. View the App: Once the app is installed, it will automatically launch on your device. You can interact with it just as you would with any other app.

Running on a Real iOS Device (macOS only)

  1. Connect Your Device: Plug in your iPhone or iPad via USB.
  2. Trust Your Computer: When prompted, select Trust on your iOS device to allow the computer to deploy apps to it.
  3. Deploy the App: In the terminal, type flutter run. Flutter will detect the connected iOS device and build the app for it.
  4. View the App: Once the build is complete, the app will launch on your device. You can now test the app in real-world conditions.

Step 4: Modifying the Flutter App

Now that you’ve successfully run your first Flutter app, let’s make a simple modification to see how easy it is to customize the code.

1. Open the lib/main.dart file in your project. This file contains the main structure of the Flutter app.

2. Find the following line of code inside the _MyHomePageState class:

appBar: AppBar(
  title: Text('Flutter Demo Home Page'),
),

3. Change the text to something more personalized, such as:

appBar: AppBar(
  title: Text('My First Flutter App'),
),

4. Save the file and watch the changes appear in real-time on your running app. Thanks to Flutter’s hot reload feature, the updated text will immediately appear without needing to restart the app.

Step 5: Exploring Widgets

Widgets are the building blocks of every Flutter app. Everything in Flutter is a widget, from simple text and buttons to complex layouts and animations. Let’s take a look at how widgets work by adding a new widget to your app.

1. In the lib/main.dart file, find the _buildCounter method, which increments the counter each time the button is pressed.

2. Add a new Text widget below the counter that displays a custom message:

    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(
          title: Text('My First Flutter App'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text(
                'You have pushed the button this many times:',
              ),
              Text(
                '$_counter',
                style: Theme.of(context).textTheme.headline4,
              ),
              Text(
                'Welcome to Flutter!',
                style: TextStyle(fontSize: 20, color: Colors.blue),
              ),
            ],
          ),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: _incrementCounter,
          tooltip: 'Increment',
          child: Icon(Icons.add),
        ),
      );
    }

    3. Save the file and see the new text message appear under the counter on your app’s interface.

      Your First Steps in Flutter

      Congratulations! You’ve successfully installed and configured Flutter, created your first Flutter project, and modified the code to make your app unique. You’ve also explored how to run your app on emulators and real devices for both Android and iOS. With these foundational skills, you’re well-equipped to dive deeper into Flutter and start building more complex, cross-platform applications.

      The next steps involve learning more about Flutter widgets, managing state, and integrating features such as navigation, networking, and animations into your apps. As you gain experience, you’ll see how Flutter’s unique approach to rendering UI and its rich set of tools can help you create high-performance, beautiful applications with ease.

      Discover More

      Introduction to Dart Programming Language for Flutter Development

      Learn the fundamentals and advanced features of Dart programming for Flutter development. Explore Dart syntax,…

      Basic Robot Kinematics: Understanding Motion in Robotics

      Learn how robot kinematics, trajectory planning and dynamics work together to optimize motion in robotics…

      What is a Mobile Operating System?

      Explore what a mobile operating system is, its architecture, security features, and how it powers…

      Setting Up Your Java Development Environment: JDK Installation

      Learn how to set up your Java development environment with JDK, Maven, and Gradle. Discover…

      Introduction to Operating Systems

      Learn about the essential functions, architecture, and types of operating systems, and explore how they…

      Introduction to Robotics: A Beginner’s Guide

      Learn the basics of robotics, its applications across industries, and how to get started with…

      Click For More