0
class BookingInfoEvent with _$BookingInfoEvent {
  // another (const factory) events ...
  const factory BookingInfoEvent._search({required int mid}) = _Search;
}

class _BookingInfoSearch with _$_BookingInfoSearch {
  const factory _BookingInfoSearch.searchBySearchBar() =_SearchBySearchBar;
  const factory _BookingInfoSearch.searchByQRScan() = _SearchByQRScan;
}

I'd like to express the above code in the following way.

abstract class BookingInfoEvent {...}

abstract class _BookingInfoSearchEvent extends BookingInfoEvent {
  final int mid;
  // ... some data
  _BookingInfoSearchEvent(this.mid);
}
//
class BookingInfoBySearchBar extends _BookingInfoSearchEvent {
  BookingInfoByTextForm(int mid) : super(mid);
}

I want to use Freezed to divide the Event classes. How can I do this?

Get Malone
  • 29
  • 2

1 Answers1

1

Freezed classes can neither be extended nor implemented. So that is not possible to do.

You can however implement the abstract class BookingInfoEvent using the @Implements annotation.

So something like this:

@freezed
sealed class BookingInfoBySearchBar with _$BookingInfoBySearchBar {
  @Implements<BookingInfoEvent>()
  const factory BookingInfoBySearchBar.search() = Search;
}
Robert Sandberg
  • 6,832
  • 2
  • 12
  • 30