Skip to content

Files

Latest commit

 

History

History
29 lines (22 loc) · 614 Bytes

avoid_field_initializers_in_const_classes.md

File metadata and controls

29 lines (22 loc) · 614 Bytes

Pattern: Use of field initializer in const class

Issue: -

Description

Instead of final x = const expr;, you should write get x => const expr; and not allocate a useless field. As of April 2018 this is true for the VM, but not for code that will be compiled to JS.

Example of incorrect code:

class A {
 final a = const [];
 const A();
}

Example of correct code:

class A {
 get a => const [];
 const A();
}

Further Reading