Skip to content

Instantly share code, notes, and snippets.

@loic-sharma
Last active December 26, 2025 18:47
Show Gist options
  • Select an option

  • Save loic-sharma/c2f92e64dbe895aaa7a0e3e8ccd89a31 to your computer and use it in GitHub Desktop.

Select an option

Save loic-sharma/c2f92e64dbe895aaa7a0e3e8ccd89a31 to your computer and use it in GitHub Desktop.
Dot shorthands error on map
enum MyEnum {
value1,
value2,
}
void foo() {
// Works as expected!
final Map<MyEnum, String> myMap = <MyEnum, String>{
MyEnum.value1: 'First',
.value2: 'Second',
};
// Works as expected!
myMap[.value2] = 'Updated First';
// Error!
// The static getter 'value2' isn't defined for the context type 'Object'.
// Try correcting the name to the name of an existing static getter, or defining a getter or field named 'value2'.
myMap[.value2];
myMap.containsKey(.value2);
myMap.remove(.value2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment