IO-Design-Team / hive_ce

Hive Community Edition - A spiritual continuation of Hive v2
https://pub.dev/packages/hive_ce
Apache License 2.0
30 stars 2 forks source link

Choose where to create the hive_registrar.g.dart file #36

Open kaciula opened 2 weeks ago

kaciula commented 2 weeks ago

Is there a way to specify where to create the hive_registrar.g.dart file? Currently, it is being created in the main lib folder. I would much prefer to control where to place it in the file hierarchy (e.g closer to where the database is)

Rexios80 commented 1 week ago

There is not currently, but I am working on a new way to generate type adapters in https://github.com/IO-Design-Team/hive_ce/pull/35. I will make it so that hive_registrar.g.dart is placed in the same directory as the file containing the @GenerateAdapters annotation.

Rexios80 commented 1 week ago

I added the feature to that PR. Could you try this and see if it does what you need?

pubspec.yaml

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

Create a file where you want hive_registrar.g.dart to be containing the following:

import 'package:hive_ce/hive.dart';

part '{YOUR_FILE_NAME}.g.dart';

@GenerateAdapters([AdapterSpec<StubType>()])
class StubType {}

You could transition your project to using @GenerateAdapters, but I'm not sure how much work that would be for you (and also the feature is not quite stable yet). If you are interested in attempting the migration for science, see the documentation here.