I have a few classes that inherit from a base class. The inherited classes have fields that are not relevant for the other classes.
abstract class Game {}
class SingleplayerGame extends Game {
int level;
}
class MultiplayerGame extends Game {
int numberOfRounds;
}
I thought I could do something like this:
Game game;
String title = game is MultiplayerGame
? "Rounds: ${game.numberOfRounds.toString()}"
: game is SingleplayerGame
? "Level: ${game.level.toString()}" : "";
I'm getting the error The getter 'numberOfRounds' isn't defined for the type 'Game'
.