I've implemented enums as keys for my maps, but I'm finding that Dart doesn't provide type safety when retrieving values.
For example, the following code does not cause compilations errors:
enum Animal {Bird, Cat, Dog, Horse}
Map<Animal, String> petNames = {
Animal.Bird: 'Lucky',
Animal.Cat: 'Cleo',
Animal.Dog: 'Spot',
Animal.Horse: 'Sleven',
};
String birdName = petNames[Animal.Bird]; // Positive test
String catName = petNames[1]; // What I want to test
String dogName = petNames['two']; // My control, I expected a compilation error
print(birdName); // Output as expected: Lucky
print(catName); // Output is null
print(dogName); // Output is null
Is this a defect in Dart?