Home > Enterprise >  Why am I getting the Equatable error: The element type can't be assigned to the list type '
Why am I getting the Equatable error: The element type can't be assigned to the list type '

Time:10-15

I upgraded Flutter to v 3.3.4 and am trying to fix the null safety issues with my blocs, but have run into a problem with Equatable props. When I make one of the event properties nullable, the equatable get props shows the following error on the [tour] prop:
The element type 'Tour?' can't be assigned to the list type 'Object'.

Here is the relevant code:

part of 'tour_editor_bloc.dart';

abstract class TourEditorEvent extends Equatable {
  const TourEditorEvent();

  @override
  List<Object> get props => [];
}

class OpenTourEditor extends TourEditorEvent {
  final Tour? tour;

  OpenTourEditor({this.tour});
  @override
  List<Object> get props => [tour];
}

Thanks for any help.

CodePudding user response:

props accepts nullable data, change the abstract class props first and then OpenTourEditor

abstract class TourEditorEvent extends Equatable {
  const TourEditorEvent();

  @override
  List<Object?> get props => [];
}

class OpenTourEditor extends TourEditorEvent {
  final Tour? tour;

  OpenTourEditor({this.tour});
  @override
  List<Object?> get props => [tour];
}
  • Related