I had added multiple entities in object box and successfully build the build_runner.
flutter pun run build_runner build
.
Now, I am adding two more entities but I am getting this error - could not resolve annotation @Entity()
Trying to add entities
import 'package:formula_application/objectbox.g.dart';
import 'package:json_annotation/json_annotation.dart';
part 'stop_test_model.g.dart';
@JsonSerializable(
explicitToJson: true,
fieldRename: FieldRename.pascal,
)
@Entity()
class StopTest {
StopTest(this.id, this.name);
int id = 0;
String name;
//@Backlink()
//final routes = ToMany<RouteTest>();
factory StopTest.fromJson(Map<String, dynamic> json) =>
_$StopTestFromJson(json);
Map<String, dynamic> toJson() => _$StopTestToJson(this);
}
\\separate route test file
import 'package:formula_application/objectbox.g.dart';
import 'package:json_annotation/json_annotation.dart';
part 'route_test_model.g.dart';
@JsonSerializable(
explicitToJson: true,
fieldRename: FieldRename.pascal,
)
@Entity()
class RouteTest {
RouteTest(this.id, this.name);
int id = 0;
String name;
//final stops = ToMany<StopTest>();
factory RouteTest.fromJson(Map<String, dynamic> json) =>
_$RouteTestFromJson(json);
Map<String, dynamic> toJson() => _$RouteTestToJson(this);
}
After build_runner build command, I am getting this error
[INFO] Generating build script... [INFO] Generating build script completed, took 514ms
[INFO] Initializing inputs [INFO] Reading cached asset graph... [INFO] Reading cached asset graph completed, took 138ms
[INFO] Checking for updates since last build... [INFO] Checking for updates since last build completed, took 926ms
[INFO] Running build... [SEVERE] json_serializable:json_serializable on lib/models/test_model/route_test_model.dart:
Null check operator used on a null value [SEVERE] json_serializable:json_serializable on lib/models/test_model/stop_test_model.dart:
Null check operator used on a null value [SEVERE] objectbox_generator:resolver on lib/models/test_model/stop_test_model.dart:
line 1, column 225 of package:formula_application/models/test_model/stop_test_model.dart: Could not resolve annotation for
class StopTest
. ╷ 1 │ @Entity()
│ ^^^^^^^^^ ╵ [WARNING] objectbox_generator:resolver on lib/models/test_model/route_test_model.dart: An unexpected error was thrown trying to get location information onclass RouteTest
(ClassElementImpl).Please file an issue at https://github.com/dart-lang/source_gen/issues/new Include the contents of this warning and the stack trace along with the version of
package:source_gen
,package:analyzer
frompubspec.lock
.InconsistentAnalysisException: Requested result might be inconsistent with previously returned results
[SEVERE] objectbox_generator:resolver on lib/models/test_model/route_test_model.dart:
Could not resolve annotation for
class RouteTest
. [INFO] 4.2s elapsed, 4/6 actions completed. [INFO] Running build completed, took 4.5s[INFO] Caching finalized dependency graph... [INFO] Caching finalized dependency graph completed, took 66ms
[SEVERE] Failed after 4.6s pub finished with exit code 1
I have tried to run the same without @JsonSerializable() annotation, using the plain class. Still getting same error.
source_gen
package. A minimal reproducible example could help to get you the answer. – Krishnakrishnahobjectbox.g.dart
file was automatically imported and I didn't check that. Now, when I was checking the imports, I changed the import fromobjectbox.g.dart
to'package:objectbox/objectbox.dart'
and build is working fine now – Disturb