Show Menu
Cheatography

Dart Cheat Sheet (DRAFT) by

Dart language cheat sheet.

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Keywords

abstract
as
assert
async
await
base
break
case
catch
class
const
continue
covariant
default
deferred
do
dynamic
else
enum
export
extends
extension
external
factory
false
final
get
finally
for
Function
import
hide
if
implements
late
in
interface
is
null
library
mixin
new
part
of
on
operator
sealed
required
rethrow
return
super
set
show
static
throw
switch
sync
this
typedef
true
try
type
with
var
void
when
 
while
yield

Naming Conven­tions

Classes
UpperC­ame­lCase
MyClass
Enums
UpperC­ame­lCase
MyEnum
Extensions
UpperC­ame­lCase
MyExte­nsion
Typedefs
UpperC­ame­lCase
MyTypeDef
Fields
lowerC­ame­lCase
myField
Private fields
_lower­Cam­elCase
_myField
Functions
lowerC­ame­lCase
myFunction
Parameters
lowerC­ame­lCase
myPara­meter
Variables
lowerC­ame­lCase
myVariable
Constants
lowerC­ame­lCase
myConstant
Direct­ories, Source files, Packages & Imports
lowerc­ase­_wi­th_­und­ers­cores
my_pac­kage, main.dart

Operators

Arithmetic operators
+
,
-
,
*
,
/
,
~/
,
%
Assignment operators
=
,
+=
,
-=
,
*=
,
/=
,
~/=
,
%=
,
&=
,
|=
,
^=
,
<<=
,
>>=
,
>>>=
Bitwise operators
&
,
|
,
^
,
~
,
<<
,
>>
,
>>>
Comparison operators
==
,
!=
,
<
,
>
,
<=
,
>=
Condit­ional operator
? :
Logical operators
!
,
&&
,
||
Function applic­ation
()
Subscript access
[]
Condit­ional subscript access
?[]
Member access
.
Condit­ional member access
?.
Non-null assertion operator
!
Unary operators
++
,
--

Comments

// This is a single line comment.
/* This is a multi-line comment. */
/// This is a doc comment.

String Interp­olation

$expr
${expr}
int a = 2;

int b = 2;

print
("Sum of $a and $b is ${a + b}"); // Sum of 2 and 2 is 4

String Concat­enation

expr1 + expr2 + ... + exprn
String str1 = 
"
Hello
";

String str2 = 
"
World
";

print
(str1 + " " + str2);

Main Function

void main() {
  // Some code
}

Variables

T variableName = value;
int age = 21;

double height = 1.75;

var
 date
Of
Birth
 = 2003;

String name = 
"
Jack
";

bool isHuman = true;

Imports

import library_name;
import 'dart:io';

import
 'dart
:math';

import
 'dart
:core';
 

Branches

if (condition) {
...

}
else if (condition) {
...

} else {
...

}
switch (value) {
case value1:
...

break;
case value2:
...

break;
...

default:
...

break;
}

Loops

for (
...
; condition; 
...
) {
...

}
while (condition) {
...

}
do {
...

} while (condition);
 

Functions

T 
functi­onName
(
parame­ter(s)
) {

   
...
}
static T 
functi­onName
(
parame­ter(s)
) {

   
...
}