notes
Introduction to the
Define a function
saySomething(String something) {
print(something);
}
Copy the code
Use to call the function defined above
main() {
final String h = 'Hi';
saySomething(h);
}
Copy the code
annotation
/ / comment
Copy the code
type
int
Copy the code
The numerical
10
Copy the code
Console printing
print(a)Copy the code
string
'Hello world'
Copy the code
String interpolation
String s1 = 'Hi';
const String s4 = "He say ${s1}";
Copy the code
Program entrance
main() // The function that must be declared when the program is running
Copy the code
Variable declarations
var abc = 1; // one of the ways to declare variables
Copy the code
Important concepts
- The value placed in a variable must be an object. All objects are instances of classes, whether numbers, functions, or null. Also, all objects inherit from
Object
Class. - Although it is a strongly typed programming language, it is possible not to use Type annotations because
Dart
The ability to infer types from values. Can be used if there is no expected typedynamic
To the statement. Dart
Generic types are supported, for exampleList<int>
(a list of integers), orList<dynamic>
(Unqualified type list).Dart
Support for top-level functions, as inmain()
, and functions bound to classes or objects (static and instance methods, respectively), as well as functions that can be created within functions.Dart
Support for top-level variables, as well as variables (static and instance variables) bound to classes or objects. Instance variables are sometimes called fields or properties.- although
Java
It’s also an object-oriented programming language, butDart
There is nopublic
.protected
andprivate
Keywords. If you want to declare a private variable, you simply prefix its identifier with an underscore (_). - The identifier must start with an underscore or a letter and can be followed by digits. Other special characters are not supported.
Dart
Both expressions and statements are supported (statements usually contain one or more expressions, but expressions cannot contain statements directly).Dart
The development tool provides two prompts:warning
anderror
.warning
They just indicate that the code may not work, but they don’t stop the program from executing.error
Appears either at compile time or at run time. Compile-time errors prevent code execution, while run-time errors cause code execution to throw exceptions.
keywords
abstract2 | dynamic2 | implements2 | show1 |
---|---|---|---|
as2 | else | import2 | static2 |
assert | enum | in | super |
async1 | export2 | interface2 | switch |
await3 | extends | is | sync1 |
break | external2 | library2 | this |
case | factory2 | mixin2 | throw |
catch | false | new | true |
class | final | null | try |
const | finally | on1 | typedef2 |
continue | for | operator2 | var |
covariant2 | Function2 | part2 | void |
default | get2 | rethrow | while |
deferred2 | hide1 | return | with |
do | if | set2 | yield3 |
Every programming language has its own specific reserved words, and Dart is no exception. When developing, we should avoid using reserved words as identifiers. Corner markers can still be used if necessary.
-
Context keywords that are valid only in certain locations. Can be used as an identifier in most places.
-
Built-in identifiers. To simplify the task of porting JavaScript code to Dart, these keywords are valid identifiers in most places, but they cannot be used as class or type names, nor as import prefixes.
-
A related update to asynchronous support, added after 1.0 release, is a limited reserved word. You cannot use await or yield as identifiers in the body of any function labeled async, async * or sync *.
Identifier: used as the name of a variable, function, or class.
The learning
Dart is an Object Oriented Programming (OOP) language that has a lot of Java in it. Dart is an Object Oriented Programming (OOP) language that has a lot of Java in it. For Javascript, a lot of the writing, usage, and concepts are similar to Javascript, but for those of you who have learned Typescript, it’s faster to learn.