Skip to content

Instantly share code, notes, and snippets.

@nikli2009
Last active July 3, 2019 08:18
Show Gist options
  • Save nikli2009/538fbc62cfcc69e8ae0033a6129b71b8 to your computer and use it in GitHub Desktop.
Save nikli2009/538fbc62cfcc69e8ae0033a6129b71b8 to your computer and use it in GitHub Desktop.
Dart Const / Final
import 'dart:math';
void main() {
const String USER_NAME = 'nikk';
// USER_NAME = 'wenyan'; => Error
final String USER_ADDRESS = 'China';
// USER_ADDRESS = 'United States'; => Error
// ------------------------------------
// Runtime Value Assignment
// const int USER_AGE = gen();
// print('const - $USER_AGE'); => Error
final int AMY_ADDRESS = gen();
print('final - $AMY_ADDRESS'); // => Works
// try assign new value for final
// AMY_ADDRESS = gen(); => Error
}
int gen() {
return Random().nextInt(5);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment