I am getting this error when I try to use switch case in dart. I have an abstract class and two classes extending it. See the code below
abstract class BankEvent{}
class FetchBanks extends BankEvent{}
class DeleteBank extends BankEvent{
final int bankId;
DeleteBank(this.bankId);
}
I have to make some implementations inside the handleEvents method depends on the instance of the class I am receiving as parameter. But I am getting the error (The switch case expression type 'Type' must be a subtype of the switch expression type 'BankEvent') in the case statement of switch case. My code for the switch case implementation is below
handleEvents(BankEvent bankEvent){
switch(bankEvent){
case FetchBanks:
break;
}
}
FetchBanks
is of typeClass
, which might be causing the error. Try modify the switch in either respect and see if it removes the error. – Hansiainswitch(bankevent)
withswitch(bankevent.getClass())
. – Hansiain