Dart Flashcards
Dart
synchronous operation
A synchronous operation blocks other operations from executing until it completes.
Dart
synchronous function
A synchronous function only performs synchronous operations.
Dart
asynchronous operation
Once initiated, an asynchronous operation allows other operations to execute before it completes.
Dart
asynchronous function
An asynchronous function performs at least one asynchronous operation and can also perform synchronous operations.
Dart Async
What is a future
A future represents the result of an asynchronous operation, and can have two states: uncompleted or completed.
Dart async
Uncompleted
Uncompleted is a Dart term referring to the state of a future before it has produced a value.
Dart async
What happens when you call an asynchronous function?
It returns an uncompleted future. That future is waiting for the function’s asynchronous operation to finish or to throw an error.
Dart async
future vs Future
Future: the Dart Future class.
future: an instance of the Dart Future class.
Dart async
Completed
When the operation completes, producing either a value or throw an Error.
Dart async
If a future doesn’t produce a usable value, what is the type?
```dart
Future<void>
~~~</void>
Dart async
The two states of a future.
Uncompleted or completed
Use cases when initializing a variable using late can be handy
The variable might not be needed, and initializing it is costly.
You’re initializing an instance variable, and its initializer needs access to this.
Use cases for the late keyword
Declaring a non-nullable variable that’s initialized after its declaration.
Lazily initializing a variable.
Instance variables can be […] but not […]
Final, const
Differentiate Final and const modifiers
Although a final object cannot be modified, its fields can be changed. In comparison, a const object and its fields cannot be changed: they’re immutable.
Differentiate Final and const modifiers
Although a final object cannot be modified, its fields can be changed. In comparison, a const object and its fields cannot be changed: they’re immutable.
Can we use type checks and casts, collection-if, spread operators in constants?
Provide an example
Yes
const Object i = 3; // Where i is a const Object with an int value…
const list = [i as int]; // Use a typecast.
const map = {if (i is int) i: ‘int’}; // Use is and collection if.
const set = {if (list is List<int>) ...list}; // ...and a spread.</int>
Can we use type checks and casts, collection-if, spread operators in constants?
Provide an example
Yes
const Object i = 3; // Where i is a const Object with an int value…
const list = [i as int]; // Use a typecast.
const map = {if (i is int) i: ‘int’}; // Use is and collection if.
const set = {if (list is List<int>) ...list}; // ...and a spread.</int>
Only constants can hold constant values? Provide an example
No
var foo = const [];
final bar = const [];
const baz = []; // Equivalent to const []
Provide examples of unary postfix operators.
What is the associativity of them?
They don’s have associativity
expr++
expr–
()
[]
?[]
.
?.
!
What is created when we use operators?
Expressions