I want to create a model like the following, but the .g.
file for isar
is not being generated.
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:isar/isar.dart';
part 'model.freezed.dart';
part 'model.g.dart';
@freezed
@Collection(ignore: {'copyWith'})
class Model with _$Model {
const factory Model({
required Id id,
required String name,
}) = _Model;
const Model._();
}
error:
Target of URI hasn't been generated: 'package:my_app/entity/model.g.dart'.
Try running the generator that will generate the file referenced by the URI.
How can I make freezed
and isar
coexist and generate files together?
In your pubspec.yaml file, use latest isar and freezed package,
isar: ^4.0.0-dev.14
isar_flutter_libs: ^4.0.0-dev.14
freezed_annotation: ^2.4.1
In your model.dart class, change Id id ๐ int id
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:isar/isar.dart';
part 'model.freezed.dart';
part 'model.g.dart';
@freezed
@Collection(ignore: {'copyWith'})
class Model with _$Model {
const factory Model({
// required Id id, //Don't use thisโ
required int id, //Use this โ
required String name,
}) = _Model;
const Model._();
}
Then run this command in your terminal
dart run build_runner build --delete-conflicting-outputs
This will generate both model.freezed.dart, model.g.dart file together.
For breaking in ISAR v4, read it isar 4.0.0-dev.14 changelog.