Flutter

Dart Essentials

1. Data Type

1.1 Core Data Types

Type Description Example
int Integer (whole number) int a = 10;
double Floating-point number double b = 3.14;
num Supertype of int and double num x = 5.5;
String Text (UTF-16 string) String s = "Hello";
bool Boolean (true/false) bool isOk = true;

1.2 Collection Types

Type Description Example
List Ordered collection List<int> nums = [1,2,3];
Set Unordered unique collection Set<int> s = {1,2,3};
Map Key-value pairs Map<String,int> m = {"a":1};

1.3 Special Types

Type Description Example
dynamic Can hold any type dynamic x = "Hello";
Object Base class of all types Object obj = 10;
Object? Nullable object Object? obj = null;
Null Represents null value Null n = null;

1.4 Function Types

Type Description Example
Function Function as variable Function f = () {};
Custom Function Specific function signature int Function(int,int)

1.5 Advanced Types

Type Description Example
Record Multiple values (tuple-like) (int, String) r = (1, "A");
Enum Fixed set of constants enum Color {red, blue}
typedef Type alias typedef MyInt = int;

1.6 Nullable Types

Type Description Example
int? Nullable integer int? a = null;
String? Nullable string String? s;

1.7 Type Keywords

Keyword Description
var Type inferred automatically
final Single assignment
const Compile-time constant

2. Operator

2.1. Arithmetic Operators

Operator Name Description Example Result
+AdditionAdds two values3 + 69
-SubtractionSubtracts two values7 - 52
*MultiplicationMultiplies two values3 * 26
/DivisionReturns double result7/32
~/Integer DivisionReturns integer result5 ~/ 31
%ModuloRemainder of division5 % 32

2.2. Increment & Decrement

Operator Name Description Example Code Result
++a Pre-increment Increase value before using it int a = 5;
int b = ++a;
a = 6, b = 6
a++ Post-increment Use value first, then increase int a = 5;
int b = a++;
a = 6, b = 5
--a Pre-decrement Decrease value before using it int a = 5;
int b = --a;
a = 4, b = 4
a-- Post-decrement Use value first, then decrease int a = 5;
int b = a--;
a = 4, b = 5

2.3. Assignment Operators

Operator Name Description Example
=AssignAssign valuea = 10
+=Add & Assigna = a + ba += b
-=Subtract & Assigna = a - ba -= b
*=Multiply & Assigna = a * ba *= b
/=Divide & Assigna = a / ba /= b
~/=Int Divide Assigna = a ~/ ba ~/= b
%=Modulo Assigna = a % ba %= b
??=Null AssignAssign if nulla ??= b

2.4. Comparison Operators

Operator Name Example
==Equala == b
!=Not Equala != b
>Greater Thana > b
<Less Thana < b
>=Greater or Equala >= b
<=Less or Equala <= b

2.5. Logical Operators

Operator Name Description Example
&&ANDTrue if both truea && b
||ORTrue if one is truea || b
!NOTNegates condition!a

2.6. Type Test Operators

Operator Name Description Example
isType TestTrue if object has typea is String
is!Not TypeTrue if not typea is! int

2.7. Null-aware Operators

Operator Name Description Example
??If NullReturn right if left is nulla ?? b
?.Null-aware AccessAccess if not nulla?.length
!Null AssertionForce non-nulla!.length

2.8. Cascade Operators

Operator Name Description Example
..CascadeChain multiple callsobj..a()..b()
?..Null-aware CascadeCascade if not nullobj?..a()

2.9. Other Operators

Operator Name Description Example
[]IndexAccess elementlist[0]
[]=Index AssignAssign elementlist[0] = 1
.Member AccessAccess propertyobj.name
?[]Null-aware IndexSafe index accesslist?[0]
...SpreadSpread elements[...list]
...?Null-aware SpreadSpread if not null[...?list]