You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 18, 2025. It is now read-only.
[BUG] isar_generator Crashes with "Null check operator used on a null value" for Composite Index
Description
When using a composite index in an Isar collection with fields like int and DateTime, the isar_generator fails during code generation with the error:
[SEVERE] isar:isar_generator on lib/db/models/chat_message/chat_message.dart (cached):
Null check operator used on a null value
This bug prevents the generation of the *.g.dart file, blocking the use of the collection. The issue appears related to the composite index definition, as removing the composite index allows the generator to succeed. This behavior suggests a parsing bug in isar_generator when handling composite indexes, possibly involving late fields or specific field types.
Steps to Reproduce
Create a Flutter project with Isar dependencies (isar: ^4.0.3, isar_flutter_libs: ^4.0.3).
Define a collection with a composite index on an int field referencing a DateTime field.
Run dart run build_runner build to generate the *.g.dart file.
Observe the build failure with the error: Null check operator used on a null value.
[SEVERE] isar:isar_generator on lib/db/models/chat_message/chat_message.dart (cached):
Null check operator used on a null value
[SEVERE] Failed after 99ms
No chat_message.g.dart is generated, preventing database usage.
Workarounds
Remove composite index:
@Index()
lateint sessionId;
This allows generation but loses composite index benefits.
[BUG]
isar_generatorCrashes with "Null check operator used on a null value" for Composite IndexDescription
When using a composite index in an Isar collection with fields like
intandDateTime, theisar_generatorfails during code generation with the error:This bug prevents the generation of the
*.g.dartfile, blocking the use of the collection. The issue appears related to the composite index definition, as removing the composite index allows the generator to succeed. This behavior suggests a parsing bug inisar_generatorwhen handling composite indexes, possibly involvinglatefields or specific field types.Steps to Reproduce
isar: ^4.0.3,isar_flutter_libs: ^4.0.3).intfield referencing aDateTimefield.dart run build_runner buildto generate the*.g.dartfile.Null check operator used on a null value.Code Sample
pubspec.yamlRun
Expected Behavior
isar_generatorshould successfully generatechat_message.g.dartwithout errors.sessionId,createdAt) should be created, enabling efficient queries like:isar.chatMessages .filter() .sessionIdEqualTo(123) .sortByCreatedAtDesc() .findAll();Actual Behavior
Build fails with:
No
chat_message.g.dartis generated, preventing database usage.Workarounds
Remove composite index:
This allows generation but loses composite index benefits.
Use single indexes:
This works but is less efficient for sorting queries.
Remove
latemodifiers (not viable due to null safety errors without initialization)Environment