Show Menu
Cheatography

Dart Cheat Sheet Cheat Sheet (DRAFT) by

Dart programming language

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

Variables

Create
var name = '...'
Rewrite
name = '...'
+ or -
num ++|--|­­**|// 1
Double -> Int
(num/3­­).t­­o­Int(); or num ~/ 3
if num-num=1 T or F
bool num-num == 1
var.to­Str­ing()
int? to string
list:
Var list = ['...', '...'];
Create list
list.a­­dd­(­"­­nam­­e");
add name to list
list.r­­em­o­v­e(­­"­­na­m­e­");
remove name from list
list.r­­em­o­v­eAt(4)
remove element with index 4
name = list[50]
get element with index 50
list[50] = "­­na­m­e­"
rewrite index 50 with name
list.a­­dd­A­l­l(­­['...', '...', '...'])
add all to list
list.c­­on­t­a­in­­s('...')
is ... in list?
list.c­­lear()
clear list
list.l­­ength
how long is list
list.i­­nd­e­x­Of­­('...')
index of element ... is
Set:
must be unique
setlist = {"ke­y": "­nam­e"}
map
 
Set dont have 'add' only 'addAll'
setlis­t.keys
get all keys
setlis­t.v­alues
get all values
---.to­List()
itarable -> list
setlis­t.c­ont­ain­sKe­y('­key')
is key exist?
setlis­t.c­ont­ain­sVa­lue­('v­alue')
is value exist?

Var types

String
Text
Int
Number
Bool
True/False
Double
Number with .
Final ...
creating while compil­­ation
Static ...
creating while writing code
dynamic
anything
 

Dart

dart create -t web-simple name
create dart web project
dart compile js path/t­­o/dart -o path/to/js
compile dart to js
void main() {code}
void-r­eturn nothing; main function

HTML

import 'dart:­html';
import DOM
import 'dart:­async';
import timer
Create variables using html
Button­Element btn = queryS­ele­cto­r('­#my­But­ton') as Button­Ele­ment;
 
connect button with id myButton to the btn variable
Paragr­aph­Element output = queryS­ele­cto­r('­#ou­tput') as Paragr­aph­Ele­ment;
 
connect button with id output to the output variable
DivElement divc = queryS­ele­cto­r('­#divv') as DivEle­ment;
 
connect container with id divv to the divc variable
FormEl­ement form = queryS­ele­cto­r('­#my­Form') as FormEl­ement;
 
connect form with id myForm to the form variable
working with html variables
btn.on­Cli­ck.l­is­ten­((M­ous­eEvent e) { code });
 
listen the button
output.text = 'Press­ed!';
 
Add text to output variable
output.st­yle.color = 'blue';
 
add style to output element
output.id = 'asd';
 
add id to the object
contai­ner.st­yle.di­splay = 'block';
contai­ner­-name | none or block
 
show/hide element
 
Paragr­aph­Element newElem = Paragr­aph­Ele­ment()
TAB ..id = 'newPa­rag­raph'
TAB ..text = 'new text';
contai­ner.ap­pen­d(n­ewE­lem);
container - name of container | newElem - name of variable
Create paragraph with teg and text
 
Future.de­lay­ed(­Dur­ati­on(­sec­onds: 2), () { code });
 
2sec timer
 
window.on­Key­Dow­n.l­ist­en(­(Ke­ybo­ard­Event event) { code });
output.text = 'Key: ${even­t.c­ode}';
hearing key pressing and print the key
 
form.o­nSu­bmi­t.l­ist­en(­(Event e) {
TAB e.prev­ent­Def­ault();
TAB InputE­lement nameInput = queryS­ele­cto­r('­#name') as InputE­lement;
TAB InputE­lement emailInput = queryS­ele­cto­r('­#em­ail') as InputE­lement;
TAB String name = nameIn­put.value ?? '';
TAB String email = emailI­npu­t.value ?? '';
});
 
form
value after ?? uses if value left is null
 

Comands

DateTi­­me.n­ow()
Time now

if/else, switch, while

if (1 < 2) {code}
if 1< 2 then make code
 
'if' cloud have anything that return bool
else if (2 > 1) {code}
else {code}
if ( 1>2 && 2 > 1) {code}
execute if 2 statements are true
||
or
return;
stop the function
switch
switch (name) {
get variable name
case "­nam­e1":
if variable is name1 do:
...
break;
stop switch execution
default:
if not exist do:
... }
while
while (1 < 2) {code}
execute code while ...

Cicles­/Func

for (var i = 0; i <= 5; i++) {code}
repeat 5 times
for (final name1 in list) {code}
name1 every time will be next name in list
for (var i = 0; i < list.l­ength; i++) { list[i] = "­tex­t" }
every cicle elements inside list will change
Functions
void name
return nothing
int/st­rin­g/bool name
return int/string
int/st­rin­g/bool name
must have return ...;
-
-
void name() {code}
create function
name()
call function
void name(int num) \ name(1)
get numbers
Only main func starts automa­ticaly