Created
November 24, 2019 00:39
-
-
Save thisismydesign/7f76185cac0aa74e19d35971f72acc5d to your computer and use it in GitHub Desktop.
Dart TIL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
// Typed variables raise type errors | |
var typed1 = 1; | |
// typed1 = '2'; | |
int typed2; | |
// typed2 = '2'; | |
// Dynamic types don't raise type errors | |
var a; | |
a = 1; | |
print(a); | |
a = 'we'; | |
print(a); | |
// Underscores are valid variable names | |
var _ = 'underscoer'; | |
print(_); | |
// Final variables are still copied by address and not by value | |
final List<int> list = [1, 2]; | |
print(list); | |
list.add(3); | |
print(list); | |
final List<int> list2 = list; | |
list2.add(4); | |
print(list); | |
// You can use `..` to return the object on which the method is executed (e.g. if method returns `void`) | |
[].addAll([1, 2]); // => void | |
print([]..addAll([1, 2])); // => [1, 2] | |
// Null aware assignment | |
String equalsIfNotNull; | |
equalsIfNotNull ??= 'works'; | |
print(equalsIfNotNull); // => works | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment