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 fromObjectClass.
  • Although it is a strongly typed programming language, it is possible not to use Type annotations becauseDartThe ability to infer types from values. Can be used if there is no expected typedynamicTo the statement.
  • DartGeneric types are supported, for exampleList<int>(a list of integers), orList<dynamic>(Unqualified type list).
  • DartSupport 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.
  • DartSupport 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.
  • althoughJavaIt’s also an object-oriented programming language, butDartThere is nopublic.protectedandprivateKeywords. 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.
  • DartBoth expressions and statements are supported (statements usually contain one or more expressions, but expressions cannot contain statements directly).
  • DartThe development tool provides two prompts:warninganderror.warningThey just indicate that the code may not work, but they don’t stop the program from executing.errorAppears 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.

  1. Context keywords that are valid only in certain locations. Can be used as an identifier in most places.

  2. 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.

  3. 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.