Skip to content

Instantly share code, notes, and snippets.

@savioserra
Last active January 24, 2020 13:36
Show Gist options
  • Save savioserra/f9c8574b68bdf7966beff77cfb969340 to your computer and use it in GitHub Desktop.
Save savioserra/f9c8574b68bdf7966beff77cfb969340 to your computer and use it in GitHub Desktop.
class Example {
final String someText;
const Example(this.someText);
}
void main() {
int value = 2;
value = 3; // Ok, field is not final
final int value2 = 5;
// value2 = 6; This is not ok. It is a compile-time error.
Example value3 = const Example("Hi");
value3 = Example("Hi2"); // This is ok! It is not final!
const Example value4 = Example("Hi"); // value4 is const, and also its const constructor is implicity called
// value4 = Example("what now?"); This is not allowed! Also a compile-time error.
// Note about type inference: You don't need to explicity type the variable when using final or const, so:
const value5 = Example("This is a const instance of type Example");
final value6 = 0; // Integer
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment