Created
April 15, 2021 15:35
-
-
Save misterfourtytwo/7278f610e8a43638a8c17ebc7abe78ed to your computer and use it in GitHub Desktop.
constant class field not const
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const strings = const Strings(); | |
class Strings { | |
const Strings(); | |
final Feature1 feature1 = const Feature1(); | |
// final Feature2 feature2 = const Feature2(); | |
} | |
class Feature1 { | |
const Feature1({ | |
this.text1 = 'x', | |
this.text2 = 'y', | |
}); | |
final String text1; | |
final String text2; | |
} | |
void main() { | |
final t = 'x'; | |
switch (t){ | |
case strings.feature1.text1: | |
print('t is x'); | |
break; | |
default: | |
print('t is not x'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
so, const constructors will create defined compile-time literals, BUT THE LINKS TO THOS LITERALS IN THE FIELDS ARE NOT FIXED, SO EVENT IF YOU USE CONST CONSTRUCTOR, POINTERS TO THE FIELD LITERALS ARE DEFINED ON RUN-TIME, THUS FIELDS ARE NOT CONST.