Construction of Flutter environment

1. Install the Flutter

Here, I choose to install to ~/opt directory, CD ~/opt. Then clone:

git clone -b beta https://github.com/flutter/flutter.git
Copy the code

2. Configure environment variables

Because Flutter needs to download the required resources from the authorities when it is running. Users without ladders need to configure an image server. If you want to run the Flutter command in any terminal session, you need to update the environment variables.

  • Go to your Shell’s configuration file to configure it.
  • If you use the default bash, configure ~/.bash_profile
  • If you are using ZSH (the default is ZSH on new Mac systems) then configure ~/.zshrc
Export PUB_HOSTED_URL=https://pub.flutter-io.cn export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn #Flutter configuration export Flutter =/opt/ Flutter /bin export PATH=$FLUTTER:$PATHCopy the code

When the configuration is complete, run source ~/.bash_profile. So next! We can see if the Flutter is configured. The Flutter has a Doctor detection command. Designed to detect your Flutter environment.

flutter doctor
Copy the code

The first time a flutter command (such as a flutter Doctor) is run, it downloads its own dependencies and compiles them. It will run much faster later. The missing dependencies need to be installed. After installation, run the flutter doctor command to verify that the flutter has been installed successfully.

3. Create and run the command

Start an emulator

open -a Simulator
Copy the code

Create a project

flutter create my_app
Copy the code
Creating project my_app...
  my_app/integration_test/driver.dart (created)
     ......  
  my_app/.idea/workspace.xml (created)
Running "flutter pub get" in my_app...                              4.0s
Wrote 75 files.

All done!
In order to run your application, type:

  $ cd my_app
  $ flutter run

Your application code is in my_app/lib/main.dart.
Copy the code

run

flutter run
Copy the code

4. Upgrade the Flutter

Flutter SDK 4.1 branch

The Flutter SDK has multiple branches, such as Beta, dev, master, and stable. The stable branch is the stable branch (and may also have new stable branches after a new stable version is released, such as 1.0.0). Dev and Master are the development branches. You can run the Flutter Channel to view all branches. If I run the flutter channel locally, the result is as follows:

Flutter channels:
  master
  dev
* beta
  stable
Copy the code

Branches with an “*” sign are the branches tracked by your local Flutter SDK. To switch branches, you can use the Flutter Channel beta or the Flutter Channel Master. But you can also trace the master branch so you can see the latest changes, but that’s much less stable.

4.2 Upgrading the Flutter SDK and dependencies

Upgrade the Flutter SDK with one command:

flutter upgrade
Copy the code

This command will update both the Flutter SDK and your Flutter project dependencies. If you only want to update the project dependencies (excluding the Flutter SDK), you can use the following command:

  • flutter packages getGet all dependencies for the project.
  • flutter packages upgradeGets the latest versions of all dependencies for your project.

5. Install the IDE

5.1 Installing Android Studio

Android Studio: Provides a complete IDE experience for Flutter. Go to the official website to download and install.

5.2 Installing Plug-ins

Android Studio -> Preferences -> Plugins install the Flutter plugin

During installation, thedartThe plug-in is also installed, the installation will be prompted to restart, restart is good. After you restart, you’ll see something like this.

5.3 Android License Issues

A license issue will be found when the Flutter is checked again, Flutter Doctor.

The inputflutter doctor --android-licensesOrder, and then blow y.

If the certificate is still not installed, repeat the above command, anyway, I am Y three times before Y good.

5.4 The Flutter plugin cannot be found

There is also an error when executing the Flutter Doctor. The Android Studio4.1.1 version has a bug where plug-ins are added and the error is reported. You can lower the version. Because the position of the Android Studio 4.1 plug-in has changed, when the flutter doctor command is used to detect the two plug-ins, they will still be searched at the original position, thus the plug-in cannot be found. But does not affect package compilation!!