Dart Flashcards
(35 cards)
What is required for a dart program
A main method
How should variables be named in Dart
Camel Case
How do you accomplish string interpolation in Dart
$variableName
How can you interpolate an expression in Dart?
${expression}
How do you escape special characters
/
How do you print a string without having to escape special characters?
r”stuff” - raw string
What is multi line string syntax?
”"”stuff”””
How do you do integer division?
~/
What effect does the prefix and postfix operators have?
Prefix (++x) adds and then assigns the value of x, postfix (x++) assigns the value of x and then adds
How do you write a hex number?
0x(number)
How can you print numbers in binary or hex?
(string).toRadixString((base))
Expressions
Hold a value at runtime
Statements
Do not hold a value at runtime
When is var used?
To declare variables that can be used more than once
When is final used?
For read only variables
When is const used?
For compile time constants
When is dynamic used?
When you want to be able to change the type of the variable
What are the collections in Dart
Lists, sets and Maps
What’s special about sets?
They only hold unique values
What are maps like?
Dictionaries
How can I read a file?
final lines = File(inputFile).readAsLinesSync();
What does a question mark after a variable mean?
It’s nullable
What is the if-null operator?
??, it assigns whatever is after it if the variable is null
What does this do? maybeNull ??= 0
Assigns 0 to maybeNull if it’s null