Skip to content

json_serializable: Could not resolve annotation for class xxx. #1836

@HeavySnowJakarta

Description

@HeavySnowJakarta

What happened?

when dart run realm generate:

[SEVERE] json_serializable on lib/storation/logbook.dart:

line 1, column 126 of package:ham_log/storation/logbook.dart: Could not resolve annotation for `class _Logbook`.
  ╷
1 │ @RealmModel()
  │ ^^^^^^^^^^^^^
  ╵
[INFO] realm:realm_generator on lib/storation/logbook.dart:[generate (0)] completed, took 49ms
[SEVERE] realm:realm_generator on lib/storation/logbook.dart:

line 1, column 126 of package:ham_log/storation/logbook.dart: Could not resolve annotation for `class _Logbook`.
  ╷
1 │ @RealmModel()
  │ ^^^^^^^^^^^^^
  ╵
#0      TypeChecker._computeConstantValue (package:source_gen/src/type_checker.dart:114:7)
#1      TypeChecker._annotationsWhere (package:source_gen/src/type_checker.dart:139:21)
#2      _SyncStarIterator.moveNext (dart:async-patch/async_patch.dart:595:13)
#3      SetBase.addAll (dart:collection/set.dart:58:23)
#4      _Set.addAll (dart:_compact_hash:1186:11)
#5      new LinkedHashSet.of (dart:collection/linked_hash_set.dart:193:27)
#6      Iterable.toSet (dart:core/iterable.dart:514:21)
#7      ElementEx._annotationsInfoOfExact (package:realm_generator/src/element.dart:62:53)
#8      _SyncStarIterator.moveNext (dart:async-patch/async_patch.dart:595:13)
#9      new _GrowableList._ofOther (dart:core-patch/growable_array.dart:203:26)
#10     new _GrowableList.of (dart:core-patch/growable_array.dart:152:26)
#11     new List.of (dart:core-patch/array_patch.dart:40:18)
#12     Iterable.toList (dart:core/iterable.dart:499:7)
#13     ElementEx.annotationInfoOfExact (package:realm_generator/src/element.dart:73:58)
#14     ClassElementEx.realmModelInfo (package:realm_generator/src/class_element_ex.dart:50:42)
#15     ClassElementEx.realmInfo (package:realm_generator/src/class_element_ex.dart:54:25)
#16     _extension#0.realmInfo.<anonymous closure> (package:realm_generator/src/realm_object_generator.dart:63:58)
#17     MappedIterator.moveNext (dart:_internal/iterable.dart:420:20)
#18     WhereIterator.moveNext (dart:_internal/iterable.dart:467:22)
#19     CastIterator.moveNext (dart:_internal/cast.dart:64:30)
#20     ExpandIterator.moveNext (dart:_internal/iterable.dart:506:21)
#21     new _GrowableList._ofOther (dart:core-patch/growable_array.dart:203:26)
#22     new _GrowableList.of (dart:core-patch/growable_array.dart:152:26)
#23     new List.of (dart:core-patch/array_patch.dart:40:18)
#24     Iterable.toList (dart:core/iterable.dart:499:7)
#25     RealmObjectGenerator.generate.<anonymous closure>.<anonymous closure> (package:realm_generator/src/realm_object_generator.dart:48:84)
#26     _rootRun (dart:async/zone.dart:1525:13)
#27     _CustomZone.run (dart:async/zone.dart:1422:19)
#28     _runZoned (dart:async/zone.dart:2034:6)
#29     runZonedGuarded (dart:async/zone.dart:2020:12)
#30     scopeSession (package:realm_generator/src/session.dart:29:16)
#31     RealmObjectGenerator.generate.<anonymous closure> (package:realm_generator/src/realm_object_generator.dart:45:16)
<asynchronous suspension>
#32     measure.<anonymous closure> (package:realm_generator/src/measure.dart:36:18)
<asynchronous suspension>
#33     measure (package:realm_generator/src/measure.dart:33:7)
<asynchronous suspension>
#34     RealmObjectGenerator.generate (package:realm_generator/src/realm_object_generator.dart:41:12)
<asynchronous suspension>
#35     _generate (package:source_gen/src/builder.dart:342:23)
<asynchronous suspension>
#36     Stream.toList.<anonymous closure> (dart:async/stream.dart:1418:7)
<asynchronous suspension>
#37     _Builder._generateForLibrary (package:source_gen/src/builder.dart:107:9)
<asynchronous suspension>
#38     _Builder.build (package:source_gen/src/builder.dart:99:5)
<asynchronous suspension>
#39     runBuilder.buildForInput (package:build/src/generate/run_builder.dart:83:7)
<asynchronous suspension>
#40     Future.wait.<anonymous closure> (dart:async/future.dart:528:21)
<asynchronous suspension>
#41     scopeLogAsync.<anonymous closure> (package:build/src/builder/logging.dart:32:40)
<asynchronous suspension>


in: package:ham_log/storation/logbook.dart:9:7
  ╷
8 │ @RealmModel()
9 │ class _Logbook {
  │       ^^^^^^^^
  ╵
Unexpected error. Please open an issue on: https://github.com/realm/realm-dart

[INFO] Running build completed, took 11.1s

[INFO] Caching finalized dependency graph...
[INFO] Caching finalized dependency graph completed, took 294ms

[SEVERE] Failed after 11.4s

Repro steps

flutter pub cache clean
flutter pub get
dart run realm generate

Version

Flutter 3.29.0 • channel stable • https://github.com/flutter/flutter.git Framework • revision 35c388afb5 (6 weeks ago) • 2025-02-10 12:48:41 -0800 Engine • revision f73bfc4522 Tools • Dart 3.7.0 • DevTools 2.42.2

What Atlas Services are you using?

Local Database only

What type of application is this?

Flutter Application

Client OS and version

windows 11 24h2

Code snippets

Here is related codes:

@RealmModel()
class _Logbook {
  @PrimaryKey()
  late String uuid;

  late String name;
  late String ownerCallsign;
  late String description;
  late String _defaultFreqUnitDisplay;

  late List<String> usuallyModes;
  late List<String> tags;
  late List<String> usuallyUsedCustomFieldKeys;
  late Map<String, String> customFields;
  
  FreqUnit get defaultFreqUnitDisplay =>
    string2FreqUnit(_defaultFreqUnitDisplay);
  set defaultFreqUnitDisplay(FreqUnit unit) =>
    _defaultFreqUnitDisplay = freqUnit2String(unit);
}

Stacktrace of the exception/crash you're getting

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions