Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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];
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading