dart_mappable
dart_mappable copied to clipboard
Consider importing parent mappers when using inheritance from different files
/// File-A:
@MappableEnum()
enum SomeEnum {
A,
B,
}
/// File-B:
@MappableClass()
class Foo with FooMappable {
const Foo({
required this.someEnum,
});
final SomeEnum someEnum;
}
/// File-C:
@MappableClass()
class Bar extends Foo with BarMappable {
const Bar({
required super.someEnum,
required this.someString,
});
final String someString;
}
The issue is that File-C
doesn't import File-A
and it won't complain as we're using super.someEnum
.
but the generated file will include SomeEnumMapper as InvalidType
and it needs manual import.
This is hard to spot if we're ignoring analyzing generate files and will throw at runtime.
It'd be helpful if we can auto-add imports for the needed mappers of the parent class if it's not included.
Unfortunately automatically adding imports to a source file is not possible with using build_runner. I understand the problem, but I don't know if or how I could fix it.
We are running in to this issue as well and it adds quite a lot of extra work, especially since it won't be caught before compiling. I'm not sure what a good generic solution could be yet, though.