this post was submitted on 21 Oct 2024
3 points (100.0% liked)

Flutter

643 readers
1 users here now

Flutter and the related logo are trademarks of Google LLC. We are not endorsed by or affiliated with Google LLC

founded 2 years ago
MODERATORS
 

Hello! I'm the maintainer of Hive Community Edition.

I am proposing to introduce a new annotaiton called @GenerateAdapters. This allows you to generate TypeAdapters for types without explicitly annotating any types or fields. This is much easier to maintian and also allows generating adapters for types outside the current package.

For example:

@GenerateAdapters([
  AdapterSpec<ClassSpec1>(),
  AdapterSpec<ClassSpec2>(),
  AdapterSpec<EnumSpec>(),
])
void _() {}

This will generate type adapters for all the types specified. The main difference between using @GenerateAdapters and explicit annotations is that type IDs and field indexes are determined automatically. This information is then stored in a hive_schema.yaml file which informs future generations which type IDs and field indexes are in use.

My main concern is introducing this feature in a way that allows any future changes to be non-breaking. I believe I have eliminated most of the risk by basing the annotation off of mockito. At the moment there aren't actually any fields in the AdapterSpec class, but adding any in the future will not be a breaking change.

I would really appreciate any feedback the Hive community has on this. If you want to try out the @GenerateAdapters annotation to see how it works in your project, add the following to your pubspec:

dependency_overrides:
  hive_ce:
    git:
      url: https://github.com/IO-Design-Team/hive_ce
      ref: ec6e8d7dfc81a4adb3a9ae9eca0e78bc104116d8
      path: hive
  hive_ce_generator:
    git:
      url: https://github.com/IO-Design-Team/hive_ce
      ref: ec6e8d7dfc81a4adb3a9ae9eca0e78bc104116d8
      path: hive_generator

See the new documentation here

Note that this is a breaking change for the generator, as hive_registrar.g.dart has moved to hive/hive_registrar.g.dart to not clutter the lib folder. I have created a migration guide here

no comments (yet)
sorted by: hot top controversial new old
there doesn't seem to be anything here