Dart by Example: Constants

In dart, compile-time constants can be created as longas the object's deep structure can be determined at compile time.

  1. import 'dart:math';
  2. // compile-time constants are defined using 'const'
  3. const name = "greg";
  4. // Objects can also be declared at compile-time
  5. const Rectangle bounds = const Rectangle(0, 0, 5, 5);
  6. main() {
  7. print(name);
  8. print(bounds);
  9. }
  10.  
  1. $ dart const.dart
  2. greg
  3. Rectangle (0, 0) 5 x 5

by @jryanio | source | license