Get the App
SLTechnology News&Howtos  ›  Development  › 

How to understand Dart language in Flutter

Shulou Source: shulou.com Published: 2022-06-02 17:56:48 10月04日 Update

This article mainly explains "how to understand the Dart language in Flutter". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to understand the Dart language in Flutter".

The initial experience of Dart language

Dart can be debugged and compiled in the compiler (AndroidStudio), command line (if DartSDK is installed) and web page repl.it. As this content is relatively simple, we can debug and compile directly in the web page.

We define a function that outputs the current time and outputs the current time

/ / output current time

VoidnowTime () {

Intyear=DateTime.now () year

Intmonth=DateTime.now () month

Intday=DateTime.now () day

Inthour=DateTime.now () hour

Intminute=DateTime.now () minute

Intsecond=DateTime.now () second

Stringstr='HelloWorld,Thisis$year-$month-$day$hour:$minute:$second'

Print (str)

}

Like most other languages, Dart requires the main function as the entry point for execution. We then define the main function and put the function that outputs the current time into the main function.

Voidmain () {

NowTime ()

}

Click the "run" button and the command will output

HelloWorld,Thisis2019-8-1110 4514

Now that we can simply run Dart code, let's take a look at the basic variable types of Dart

Variables and types of Dart language

In Dart, all variables can be declared with var, and of course, you can specify a specific type to declare a variable. When you use var to declare variables, the representation type is left to compiler inference. Although Dart supports the use of var to declare variables, I recommend using specific types to declare variables so that editors and compilers can use these specific types to provide you with tips for code completion or compilation alerts.

Note: by default, the values of all uninitialized variables are null, so we only need to compare with null when we determine whether the variable is initialized.

Dart is a type-safe language, and all types are object types and inherit from the top-level type Object, so the values of all variables are tired instances (that is, objects), including numbers, Boolean values, functions, and null are also inherited from Object objects.

Dart has some basic types built in, such as num, bool, String, List, and Map.

Thank you for reading, the above is the content of "how to understand the Dart language in Flutter". After the study of this article, I believe you have a deeper understanding of how to understand the Dart language in Flutter, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Type variable language function compilation output time content object compiler learning code command situation web page security next entry including premise Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Microsoft Apple MariaDB OPPO Reno