Skip to content

Instantly share code, notes, and snippets.

@Headmast
Last active September 30, 2020 08:03
Show Gist options
  • Save Headmast/bfa2d29ad3d8c03a865371f464546ee4 to your computer and use it in GitHub Desktop.
Save Headmast/bfa2d29ad3d8c03a865371f464546ee4 to your computer and use it in GitHub Desktop.
Var and const in Dart.
int a;

void awesomeFunction() {
  double b;
  int b1;
  var text = "Hello world";
  //text = a; //error: A value of type 'int' can't be assigned to a variable of type 'String'.
  dynamic dyn;
  dyn = text; // No error, works perfect.

  //final fin; // Error: The final variable ';' must be initialized.
  //const con; // Error: The const variable ';' must be initialized.
  final fin = "Finita la comedia";
  const con = 42;

  //fin = "Next value"; //  Error: Can't assign to the final variable 'fin'.
  //con = 43; // Error: Can't assign to the const variable 'con'.

  // const vs final https://news.dartlang.org/2012/06/const-static-final-oh-my.html

  double fullEnd = 12;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment