1

I have a const List. It means every item to the list is constant . I can say that notificationActions[0] is also a constant.

const  notificationActions = [
  'Category updated',
  'Sticker pack updated' ,
  'new feature Added'
];

Problem : Switch statement in dart says Case expressions must be constant, It means dart doest consider notificationActions[0] as a constant but why? here is my expression

  setTypeNotification(String type){
    switch(type)
    {
      case notificationActions[0]:
      // Some statements  
        break;
    }
  }
M.ArslanKhan
  • 3,640
  • 8
  • 34
  • 56
  • See https://stackoverflow.com/questions/62652380/in-dart-how-to-assign-a-value-from-a-const-map-to-a-const-variable. Quote from the answer: The [] operator is a method (all user-definable operators are), and you cannot call a method at compile time except for a very small number of operations on known system types. – hnnngwdlch Sep 26 '21 at 19:38

0 Answers0