ObjectBox Generator: Error: No named parameter with the name 'lazy'

Issue

I registered my ObjectBox Store as a LazySingleton with this method

setupLocatorAdditions() async {
  stackedAdditionLocator.registerLazySingletonAsync<Store>(() => openStore());
}

Which worked fine. But after multiple rebuilds from the BuildRunner the ObjectBox Generator threw this error, regardless of whether I removed the singleton registration and reran it.

lib/objectbox.g.dart:1341:67: Error: No named parameter with the name 'lazy'.
              weekDays: const fb.ListReader<int>(fb.Int8Reader(), lazy: false)
                                                                  ^^^^
../../Flutter/flutter/.pub-cache/hosted/pub.dartlang.org/objectbox-1.1.1/lib/flatbuffers/flat_buffers.dart:994:9: Context: Found this candidate, but the arguments don't match.
  const ListReader(this._elementReader);
        ^^^^^^^^^^

lib/objectbox.g.dart:1343:68: Error: No named parameter with the name 'lazy'.
              locations: const fb.ListReader<int>(fb.Int8Reader(), lazy: false)
                                                                   ^^^^
../../Flutter/flutter/.pub-cache/hosted/pub.dartlang.org/objectbox-1.1.1/lib/flatbuffers/flat_buffers.dart:994:9: Context: Found this candidate, but the arguments don't match.

  const ListReader(this._elementReader);
        ^^^^^^^^^^
2

FAILURE: Build failed with an exception.

Solution

That argument isn’t part of the released objectbox-dart v1.1.1 (it was added by this commit 13 days ago while v1.1.1 was released 19 days ago).

Looks like you’re using a mismatching generator? Can you check your pubspec.yaml if you’re using a dependency override on objectbox_generator, e.g. from git? If you’re using a dependency override you should stick to a specific commit and make sure you use it on both generator and objectbox library itself. If you don’t need the dependency override, just remove it from your pubspec.yaml.

In both cases, run pub get after making the changes and pub run build_runner build.

Answered By – vaind

Answer Checked By – Marilyn (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *