Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generator doesn't work with freezed models #414

Closed
awaik opened this issue Apr 29, 2022 · 6 comments
Closed

Generator doesn't work with freezed models #414

awaik opened this issue Apr 29, 2022 · 6 comments
Labels
invalid This doesn't seem right

Comments

@awaik
Copy link

awaik commented Apr 29, 2022

According to the documentation and closed issue #229 Objectbox supports generating with freezed.
But if I copy-paste the example from the docs - nothing happens. All classes are ok, but with freezed - nothing generated.

Basic info (please complete the following information):

  • ObjectBox version: 1.4.1
  • Flutter/Dart SDK: Flutter 2.10.4 • channel stable • Dart 2.16.2
  • Null-safety enabled: yes
  • Reproducibility: always
  • OS: macOs BigSur
  • Device/Emulator: IphoneX

Steps to reproduce

Just copy-paste an example and run
packages pub run build_runner build --delete-conflicting-outputs

part 'test_person.freezed.dart';

@Freezed()
class Person with _$Person {
  @Entity(realClass: Person)
  factory Person({
    @Id(assignable: true) int? id,
    String? name,
    int? age,
  }) = _Person;
}

Expected behavior

Should generate ModelEntity in objectbox.g.dart

@awaik awaik added the bug Something isn't working label Apr 29, 2022
@awaik awaik changed the title Do not generate objects with freezed Generator doesn't work with freezed models Apr 29, 2022
@greenrobot-team
Copy link
Member

I assume you have set up ObjectBox as documented at https://docs.objectbox.io/getting-started?

If so, please submit a full project that we can reproduce this with.

@greenrobot-team greenrobot-team added more info required Needs more info to become actionable. Auto-closed if no response. and removed bug Something isn't working labels May 2, 2022
@awaik
Copy link
Author

awaik commented May 2, 2022

You are right. With clean project it works.

For those who might be experienced the same bug - the reason is in
auto_route_generator: ^3.2.3 (tried different versions, the result is the same)
After commenting it, starts to generate the entities with freezed.
I haven't figured out the reason, no any errors in the console, just stops to generate.

@greenrobot-team
Copy link
Member

@awaik Weird, if you ever find out if this is because something ObjectBox can improve, let us know! Closing this then!

@greenrobot-team greenrobot-team added invalid This doesn't seem right and removed more info required Needs more info to become actionable. Auto-closed if no response. labels May 3, 2022
@gorkemunuvar
Copy link

I deleted all the @Entity annotations from the freezed classes and used it only with a model without freezed. It generated files even if I installed auto_route_generator.

@redarflap
Copy link

I got exactly the same issue and found no way to work around it.

I tried limiting the scanned directories for both generatos in build.yaml
Not even disabling the auto_route_generator in the build.yaml worked.

At the moment auto_route_generator is added to pubspec.yaml, objectbox just stops generating freezed classes. It doesn't even appear in the build --verbose output anymore.

@EvgeniShmakov
Copy link

In my case it happens because objectbox runs BEFORE freezed.
You can verify it here: .dart_tool/build/entrypoint/build.dart
After manual order changing it works if you run this dart file manually.
But build_runner re-creates the old order.
So far I did not find how to order builders.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

5 participants