I wrote this simple switch case for an enum:
enum Operation {
CREATE,
UPDATE,
DELETE,
READ
}
...
void check(Operation op) {
switch(op) { // dart complains here
case Operation.CREATE:
insert();
break;
case Operation.UPDATE:
update();
break;
case Operation.DELETE:
delete();
break;
}
which complains with this error at the switch(op) line:
error: Missing case clause for 'READ'.
Try adding a case clause for the missing constant, or adding a default constant.
It gets fixed if I follow the suggestion and add the READ case or a default case.
But my question is : why is this so ? Why can't I leave out a case? What if I don't want to check that case here? I checked the dart language docs which says :
You can use enums in switch statements, and you’ll get a warning if you don’t handle all of the enum’s values
But in my case, its definitely an error and not a warning. I'm using dart for developing a flutter application (if that makes a difference).