Consider these states:
class ExerciseInitialState extends ExerciseState {}
class ExerciseLoadingState extends ExerciseState {}
class ExerciseLoadedState extends ExerciseState {
final List<Data> data;
const ExerciseLoadedState({required this.data});
@override
List<Object> get props => [data];
// total count
int get totalCount => data.length;
}
In the UI, I have to cast the state (ExerciseState
) to ExerciseLoadedState
to be able to access its property which doesn't exist in the ExerciseLoadingState
and ExerciseInitialState
:
final total = (context.read<ExerciseBloc>().state as ExerciseLoadedState).totalCount
It looks awkward to me to have to do this casting all the time. Is the only solution to add the same properties to the base class ExerciseState
?