Dart Flashcards
Dart overview
- Object oriented language
- Statically Typed
- C-Style Syntax
- Multiple Runtime Env.
Sample method
String myName () { return 'Stephen'; }
Main method
void main ( ) { … }
Variable declaration
var name = myName(); const value = 1000;
Type System
- Every value has a type
- Every variable has a type reference
- variables type cannot change
- Dart can guess type
Built-in Types
- numbers
- strings
- booleans
- lists (arrays)
- sets
- maps
- runes (Unicode char strings)
- symbols
Number types
- int -2^63 to 2^63 - 1
- double IEEE 754
- both of them are subtypes of num
var y = 1; var hex= 0xDEADBEEF; var y = 1.1; var exponents = 1.42e5;
double z = 1; // equalst to z=1.0
Numbers to String and back
int. parse(‘1’);
double. parse(‘1.1’);
1. toString();
3. 14.toStringAsFixed(2);
Bitwise Operators
«_space;» & |
What is a String?
UTF-16 unit sequence
Create Strings
var s1 = 'Single quotes work well for string literals.'; var s2 = "Double quotes work just as well."; var s3 = 'It\'s easy to escape the string delimiter.'; var s4 = "It's even easier to use the other delimiter.";
String expressions
- ${expression}
- If the expression is an identifier, you can skip the {}
var s = 'string interpolation'; 'Dart has $s, which is very handy.'
String equality
The == operator tests whether two objects are equivalent. Two strings are equivalent if they contain the same sequence of code units.
Concat Strings
You can concatenate strings using adjacent string literals or the + operator:
var s1 = 'String ' 'concatenation' " works even over line breaks.";
Multi-line string
use a triple quote with either single or double quotation marks:
var s1 = ‘’’
You can create
multi-line strings like this one.
‘’’;