DEV Community

Cover image for A Comprehensive Guide to Setting Up Flutter for Beginner Developers
kargathara Aakash
kargathara Aakash

Posted on

A Comprehensive Guide to Setting Up Flutter for Beginner Developers

Introduction:

Are you ready to embark on your Flutter development journey? This tutorial is designed to guide beginners through the process of setting up Flutter in Android Studio and creating their first "Hello World" app. By the end of this tutorial, you'll have a solid foundation to start building your own Flutter apps. Let's get started!

Step 1: Downloading and Installing Flutter:

  • Visit the official Flutter website at flutter.dev and click on the "Get Started" button.
  • Choose your operating system (Windows, macOS, or Linux) and click on the respective download link.
  • Once the download is complete, extract the downloaded file to a location of your choice.
  • Add the Flutter SDK path to your system's environment variables:

Windows:

  • Open the Control Panel and go to "System and Security" -> "System" -> "Advanced system settings".
  • Click on the "Environment Variables" button.
  • In the "System variables" section, select the "Path" variable and click "Edit".
  • Click on "New" and add the path to the "flutter\bin" directory (e.g., C:\flutter\bin).
  • Click "OK" to save the changes.

macOS/Linux:

  • Open a terminal and navigate to your home directory.
  • Run the command nano .bash_profile to open the file in the nano editor (or use any text editor of your choice).
  • Add the following line at the end of the file:
export PATH="$PATH:/path/to/flutter/bin"

Enter fullscreen mode Exit fullscreen mode

Replace /path/to/flutter with the actual path to the Flutter SDK directory.

  • Press Ctrl+X to exit, then press Y to save the changes, and press Enter to confirm the file name.
  • Run the command source .bash_profile to apply the changes to the current terminal session. That completes step 1 of setting up Flutter. Next, we will move on to step 2: Setting Up Android Studio.

Step 2: Setting Up Android Studio:

1. Download and Install Android Studio:

  • Visit the official Android Studio website at developer.android.com/studio.
  • Click on the "Download Android Studio" button.
  • Choose the appropriate version for your operating system and click "Download."
  • Once the download is complete, run the downloaded installer and follow the on-screen instructions to install Android Studio.
  • Open Android Studio and Set Up Flutter Plugin:

2. Open Android Studio on your computer.

  • If you're launching Android Studio for the first time, you'll be prompted to import settings from a previous installation. Choose your preference and proceed.
  • On the Welcome screen, click on "Configure" in the bottom-right corner and select "Plugins."
  • In the Plugins window, click on the "Marketplace" tab.
  • Search for "Flutter" in the search bar.
  • Click the "Install" button next to the "Flutter" plugin.
  • Follow the on-screen prompts to install the plugin and restart Android Studio when prompted.

3. Configure Flutter SDK Path in Android Studio:

  • Once Android Studio restarts, go to "File" -> "Settings" (or "Preferences" on macOS) to open the Settings/Preferences window.
  • In the left sidebar, navigate to "Languages & Frameworks" -> "Flutter."
  • Click on the "SDK Path" field and then click the folder icon on the right.
  • Locate and select the Flutter SDK directory (the folder where you extracted the Flutter SDK in Step 1).
  • Click "Apply" and then "OK" to save the settings.

That completes step 2 of setting up Flutter. Next, we will move on to step 3: Creating a New Flutter Project.

Step 3: Creating a New Flutter Project:

1. Open Android Studio and click on "Start a new Flutter project" or go to "File" -> "New" -> "New Flutter Project".

2. Choose a Flutter application template:

  • Select "Flutter Application" if you want to create a basic Flutter app.
  • Select "Flutter Plugin" if you want to create a plugin package that can be used by other Flutter apps.
  • Select "Flutter Package" if you want to create a reusable Flutter package.

3. Click "Next" to proceed.

4. Specify the project details:

  • Enter the project name (e.g., "HelloWorld").
  • Choose the project location.
  • Select the programming language (Java or Kotlin) for Android.
  • Select the organization name (optional).
  • Ensure that the Flutter SDK path is correctly displayed.
  • Click "Finish" to create the project.

5. Android Studio will generate the project files and dependencies. This process may take a few moments.

6. Once the project is created, you will see the project structure in the Android Studio's Project view.

Congratulations! You have successfully created a new Flutter project. In the next step, we will write the "Hello World" code in Flutter.

Step 4: Writing Your First Flutter Code:

  1. Open the lib/main.dart file in your Flutter project. This file contains the main entry point for your Flutter app.
  2. Replace the existing code with the following "Hello World" code:
import 'package:flutter/material.dart';

void main() {
  runApp(
    MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Hello World'),
        ),
        body: Center(
          child: Text('Hello, Flutter!'),
        ),
      ),
    ),
  );
}
Enter fullscreen mode Exit fullscreen mode

1. Save the file.

Explanation:

  • The import 'package:flutter/material.dart'; statement imports the necessary Flutter framework.
  • The main() function is the entry point of the Flutter app. It calls the runApp() function to run the Flutter application.
  • The MaterialApp widget represents the root of the Flutter app and provides basic app functionalities.
  • The Scaffold widget provides a basic app structure, including an app bar and a body.
  • The AppBar widget represents the app bar at the top of the screen with a title.
  • The Center widget aligns its child widget in the center of the screen.
  • The Text widget displays the "Hello, Flutter!" text.

That's it! You have written the "Hello World" code in Flutter. In the next step, we will run your app on an emulator or device to see the output.

Step 5: Running Your App:

Before running your app, ensure that you have set up an Android device or emulator.
For setup emulator: click here

Follow these steps to run your Flutter app:

  1. Open Android Studio.
  2. Make sure your device or emulator is connected and recognized by Android Studio.
  3. Click on the green "Run" button in the toolbar, or go to "Run" -> "Run 'main.dart'".
  4. In the "Select Deployment Target" window, choose the target device or emulator where you want to run your app.
  5. Click "OK" to start the app installation and launch process
  6. Android Studio will build the app, install it on the selected device/emulator, and launch it automatically.
  7. After a few moments, you should see your "Hello World" app running on the device/emulator.

Congratulations! You have successfully run your Flutter "Hello World" app. You can now see the "Hello, Flutter!" text displayed on the screen.

Take some time to explore the app, interact with it, and get familiar with the basic Flutter UI elements.

In the next step, we will conclude the tutorial and provide some additional resources for further learning and exploration.

Step 6: Conclusion and Further Learning:

Congratulations on completing your first Flutter app! You've taken the initial steps to become a Flutter developer. Here are some additional resources and next steps to continue your Flutter journey:

For further learning and exploration refer this: click here

๐Ÿ‘ Like, โค๏ธ Love, and ๐Ÿ”” Follow

Top comments (0)