Is there a way to define polymorphic copyWith method with freezed? I'm doing something like this right now, but I don't wanna repeat myself...
abstract class Schedulable {
String get title;
DateTime get start;
DateTime get end;
}
@freezed
abstract class Task with _$Task implements Schedulable {
const factory Task(
{String title,
@required @TimestampConverter() DateTime start,
@required @TimestampConverter() DateTime end,
String taskOnlyField }) = _Task;
}
@freezed
abstract class TimeEntry with _$TimeEntry implements Schedulable {
const factory TimeEntry(
{String title,
@required @TimestampConverter() DateTime start,
@required @TimestampConverter() DateTime end,
String timeEntryOnlyField }) = _TimeEntry;
}
if (schedule is Task) {
schedule = (schedule as Task).copyWith(start: start);
} else if (schedule is TimeEntry) {
schedule = (schedule as TimeEntry).copyWith(start: start);
}