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';

3. // compile-time constants are defined using 'const'
4. const name = "greg";

6. // Objects can also be declared at compile-time
7. const Rectangle bounds = const Rectangle(0, 0, 5, 5);

9. main() {
10. print(name);
11. print(bounds);
12. }
1. $ dart const.dart
2. greg
3. Rectangle (0, 0) 5 x 5

by @jryanio | source | license