How to install and run the Flutter application in Windows?
Flutter is Google’s UI toolkit for building natively compiled mobile applications with a single codebase. With a single code, we make a native-looking performant application for both android and iOS. Flutter uses a Dart programming language. The installation process of Flutter on your machine is straightforward.
Installation process for Windows
- Get the flutter SDK
i. Download the flutter SDK from here. (SDK version 3.3.1 stable)
ii. Extract the SDK zip and place the flutter folder in the desired location (maybe C:\src\flutter)
Note: Installing flutter in a directory like C:\Program Files may require some privileges.
2. Update your path
Go to Environment Variables. And under the user variables, you can find Path. If not, you can create a variable named Path.
In the path, you need to paste a full path to flutter\bin as its value.
You can always run the following command to check the status of your flutter installation:
flutter doctor
Here, I’ve already installed the Android studio and required SDKs, thus there are no any errors. But if you have some error like :
✗ Android SDK is missing command-line tools
Android Studio Setup
Then, you need to install Android Studio. This installs the latest Android SDK, Android SDK Command-line Tools, and Android SDK Build-Tools, which are required by Flutter when developing for Android.
You can use an Android Studio or Visual Studio Code for the code editor. And to run and test the app, you can either do it on a physical device or on an emulator using AVD manager.
- Running on an emulator
Open ADV manager on Android Studio.
Create a new virtual device. Select the phone model, android version, etc., and continue installing the device.
Once you have a virtual device, you can run it right from the manager.
- Running on a physical device
To run on your device, open the Developer Tools on your mobile. If the option is not shown there, you may need to tap on the build number multiple times until it says, “You are a developer now”.
In the developer options, there is an option for USB debugging which you need to enable.
Then, You may need to install the Google USB Driver.
Now, plug your device into the computer using a USB cable and authorize your device with the computer. Now your device should be connected.
To check the connected devices, you need to run: flutter devices command.
Again, to verify the setup, you need to run: flutter doctor to make sure there are not any issues.
Creating a Flutter Project
After all these setups, you can create and run your brand new flutter project easily with a couple of commands:
Type flutter on the terminal to view all the commands.
To create a new project, run flutter create <app_name>
Problem: Using the project name in camelCase produces an error.
Solution: As the flutter, the project name requires to be a valid dart package name. It suggests we use lowercase_with_underscores for package names.
A valid example would be flutter create my_flutter_app
This will create a flutter project in the specified directory.
Running a Flutter App
Go into your project directory and from there, run the following command:
flutter run
Your devices should be connected to run the app, either a physical device or virtual device which we’ve already set up in the above part.
Inside of VS Code, you can see the connected device name at the bottom status bar.
Your main working code is located in the lib/main.dart file.
Congrats. You’ve successfully run your first flutter app. :)
Flutter also supports hot reloading and hot restarting which makes our development faster. For hot reloading, type “r” in the terminal, or you can tweak some settings to hot reload every time on save.