ref – https://stackoverflow.com/questions/50431055/what-is-the-difference-between-the-const-and-final-keywords-in-dart
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
void main() { print("Hello, World!"); // Should use final if you don't know the value at compile time, // and it will be calculated/grabbed at runtime. // However, if the value is known at compile, use const. final a = { "hoho": "heheheh", }; print(a["hoho"]); // final: ok √ // const: error: Uncaught Error: Unsupported operation: Cannot modify unmodifiable Map a["hoho"] = "hihihihi"; print(a); // same // final: error, variable 'a' can only be set once. // const: can't be re-assigned. // a = { // "name":"ricky" // }; } |