Based on Dart version 2.4, this article extracts some language highlights for students with a certain language foundation to get started quickly.

Operator (Operators)

?? ?? =

When a is null, use value to assign:

a = a == null ? value: a;  // java
a = a || value;  // javascript 
Copy the code

Use?? In Dart? You can abbreviate the above code,

a = a ?? value; // dart
Copy the code

Further, using compound assignment makes the code simpler,

a ?? = value;Copy the code

as is is!

Used to check object types at run time

The operator said
as Type cast
is Returns if the object is of the specified typeTrue
is! In contrast to the is

Such as:

if (emp is Person) {
  emp.firstName = 'Bob';
}
(emp as Person).firstName = 'Bob'; 
Copy the code

.

The cascade operator, a continuous operation on the same object, is as follows:

var button = querySelector('#confirm');
button.text = 'Confirm';
button.classes.add('important');
button.onClick.listen((e) => window.alert('Confirmed! '));
Copy the code

Use.. The operator can be abbreviated:

querySelector('#confirm') // Get an object. .. text ='Confirm'// Use its members. .. classes.add('important')
  ..onClick.listen((e) => window.alert('Confirmed! '));
Copy the code

.

Expansion operations for Collection classes to make it easier to insert elements into a Collection.

final list = [1.2.3];
final list2 = [
    ...list, 
    4];  // [1, 2, 3, 4]
Copy the code

At present… Object expansion is not supported yet, which is not as convenient as ES6

Types (Types)

An Array or a List

Dart no longer has a separate array type, but a List.

final list = [1.2.3];
final list = <int> [1.2.3];
Copy the code

Because Dart has a wealth of operators, a List can use array-like operations. For example, the subscript operator [].

final first = list[0];
Copy the code

Functions (Functions provides)

Optional named parameter

Optional position parameter

Classes (Classes)

Generics (up)

Reference Resources:

  • The dart. Dev/guides/lang…