isar icon indicating copy to clipboard operation
isar copied to clipboard

Include better error message when extending from Equatable

Open alestiago opened this issue 2 years ago • 3 comments

Is your feature request related to a problem? Please describe. Whenever a model extends a class from an external package it is not possible to add @ignore on its members. For example, this happens when extending from Equatable, it even has its own dedicated discussion https://github.com/isar/isar/discussions/648.

When running the isar_generator the error messages are quite handy but suggesting to add @Collection(inheritance: false) (or equivalent) is not included within the error message.

Describe the solution you'd like As a developer, I would like the isar_generator to inform me to include @Collection(inheritance: false) whenever I'm inheriting from an external library (or any other case where adding @ignore in the super's member is not possible).

Version

  • Platform: N/A
  • Flutter version: 3.13.7
  • Isar version: ^3.1.0+1

alestiago avatar Oct 14 '23 18:10 alestiago

100% agree--I only was able to resolve my issue after finding this and reading the linked discussion above (which indicated I needed both @ignore and @Collection(inheritance: false), which I did not expect!

btrautmann avatar Nov 02 '23 14:11 btrautmann

I tried many times mixing @collection with other packages, including freeze and equatable. The only one that works without any issues is dart_mappable, which also has equality.

I have not tried to use with @ignore though

vicenterusso avatar Nov 02 '23 14:11 vicenterusso

Yeah you'll need @Collection (capital C) with inheritance: false and @ignore on the members you want Isar to ignore before it'll work. Took a lot of fiddling until I fully read the above discussion to actually get it. I'm now able to use Equatable which has been huge because I have a lot of Riverpod Providers that expose Streams of Isar objects and they were emitting redundant Lists of info. With Equatable I'm able to do something like:

yield* CombineLatestStream.combine2(budgets, currencyFormats, (bs, cfs) {
    return bs.map((e) => e.toBudget(cfs.firstWhereOrNull((c) => c.budgetId == e.uuid))).toList();
  }).distinct((a, b) { // Use `distinct` to avoid emitting duplicate data
    return const DeepCollectionEquality.unordered().equals(a, b);
  });

Which avoids any flickering in the UI going from Loaded to Loading to Loaded state for no reason 👍

btrautmann avatar Nov 02 '23 14:11 btrautmann