Why can I not get a compile-time error referencing a non-existent key in a Dart map?

23 Views Asked by At

I am new to Dart and was expecting to get a compile-time error for the following code:

  final Map screens = const {
    "START": 'start_screen',
    "QUESTIONS": 'questions_screen',
    "RESULTS": 'result_screen',
  };

...
  activeScreen = screens['QUESTIONS1']!;

I know that I can use containsKey to find it a real time, but if my map is const, why cannot the Dart compiler find this code error?

0

There are 0 best solutions below