Combining multiple SOURCEs into one single TARGET
Hi,
I don't know if there's a workaround for this.
In my project I have the case where one single class (form) is a combination of several other classes (model objects that reflect tables from the database).
I have for example these 2 models:
@freezed
class EquipmentBase with _$EquipmentBase {
const factory EquipmentBase({
required int id,
required String name,
}) = _EquipmentBase;
}
@freezed
class Equipment with _$Equipment {
const factory Equipment({
required int id,
required int type,
}) = _Equipment;
}
And this single form object:
@freezed
class EquipmentForm with _$EquipmentForm {
const factory EquipmentForm({
required int id,
required String name,
required int type,
}) = _EquipmentForm;
}
I'd like to be able to get an EquipmentForm (TARGET) based on both Equipment and EquipmentBase (SOURCES)
At the moment I just make a double conversion and combine manually the properties at the end:
- Convert EquipmentBase to EquipmentForm
- Convert Equipment to EquipmentForm
- Use copyWith() to combine both EquipmentForm objects
Is there anyway I can do this at the moment? Maybe through a custom converter or similar?
Thanks.
Hi, at the moment, no. We would like to support this case with normal classes. (not for sealed/freezed, reasons similar to #148).
The implementation could be done for N input classes to 1 output, probably as a new MapTypeMultiple or something like that. But in the near future, I don't think we will have enough time to implement that.
You are, however, free to take the initiative if you'd like to!
Thanks @tenhobi
Not a big deal for me at the moment either, just an improvement for the future.