Flutter series articles - Flutter environment construction and Dart foundation

Flutter is an open source, high-performance mobile application development framework launched by Google, which can develop Android and iOS applications with a set of code bases. Dart is the programming language used by Flutter. Let's take a look at how to set up a Flutter development environment and understand the basics of the Dart language.

1. Flutter environment construction

1. Install the Flutter SDK

First, visit the Flutter official website to download the Flutter SDK. Select the version suitable for your operating system (Windows, MacOS, Linux), and unzip it to the directory you want to save after the download is complete.

Note that the channel version of Flutter will keep changing, please refer to the official website of Flutter. In addition, in mainland China, if you want to get the installation package list or download the installation package normally, you may need to go over the wall. Readers can also go to the Flutter github project to download the installation package, address: https://github.com/flutter/flutter/ releases.

Unzip the installation package zip to the path where you want to install the Flutter SDK (eg: C:\src\flutter; be careful not to install flutter to a path that requires some high permissions such as C:\Program Files\).

Find flutter_console.bat under the flutter file in the Flutter installation directory, double-click to run it and start the flutter command line. Next, you can run the flutter command on the Flutter command line.

2. Set environment variables

Add Flutter's bin directory to your PATH environment variable. On Windows, you can set it in the system environment variable; on Mac or Linux, you can add export PATH="$PATH:pwd/ flutter/bin".

3. Install and set up the editor

It is recommended to use VS Code or Android Studio, both of which support Flutter development, and both have rich plug-ins to help you improve development efficiency. Search and install the "Flutter" and "Dart" plugins in the corresponding plugin store.

4. Create your first Flutter project

The first time you run a flutter command (like flutter doctor), it downloads it's own dependencies and compiles itself. It will be much faster to run later. The missing dependencies need to be installed. After the installation is complete, run the flutter doctor command to verify whether the installation is successful.

In a terminal, run the following command:

flutter create my_first_flutter_app
cd my_first_flutter_app
flutter run //flutter run -d all

The flutter run command starts the emulator and runs your app in the emulator. You should now see the Flutter welcome screen.

5. Note that
you will definitely encounter problems during the process of setting up the running environment. You can use "flutter doctor" to run on the console, and just install what you need to install when prompted.
Here's the problem I'm having:

What is installed includes:

2. Dart foundation

Dart is an object-oriented, class-defined, single-inheritance language, and its syntactic sugar is very similar to other programming languages ​​(such as Java, JavaScript, and C). Let's look at a few basic knowledge points of Dart.

  1. variables and types

Dart is a strongly typed language that supports basic data types such as int, double, String, bool, etc.

int age = 20;
double height = 1.88;
String name = 'John';
bool isOld = false;

Dart also has type inference, you can use the var keyword to let Dart infer the type automatically.

var weight = 70.5; // Dart会自动推断为double类型
  1. control flow

Dart supports common control flow statements, such as if-else, for, while, etc.

if (isOld) {
  print('$name is old');
} else {
  print('$name is young');
}

for (var i = 0; i < 10; i++) {
  print(i);
}

while (age > 0) {
  age--;
}
  1. function

Functions are first-class citizens in Dart, and support return value type declarations, parameter type declarations, arrow syntax, etc.

String greet(String name) {
  return 'Hello, $name';
}

var greet = (String name) => 'Hello, $name'; // 箭头函数,只能有一行代码

The above is a brief introduction to the construction of the Flutter environment and the foundation of Dart. For a more in-depth understanding and learning of the Dart language, you can refer to the official documentation of Dart . Since we have a little foundation in other languages, we will not elaborate on these contents. We can check the details during use. After learning these basics, you can start using Flutter for application development. I wish you a happy study!

Guess you like

Origin blog.csdn.net/xudepeng0813/article/details/131703473