Skip to content

Instantly share code, notes, and snippets.

@thisismydesign
Created November 24, 2019 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thisismydesign/7f76185cac0aa74e19d35971f72acc5d to your computer and use it in GitHub Desktop.
Save thisismydesign/7f76185cac0aa74e19d35971f72acc5d to your computer and use it in GitHub Desktop.
Dart TIL
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