While using isar with freezed, getting Unsupported type error for copyWith getter method while build runner.
Here is the model class for which the build_runner is failing.
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:isar/isar.dart';
part 'api_response_model.freezed.dart';
part 'api_response_model.g.dart';
@collection
@freezed
class ApiResponseModel with _$ApiResponseModel {
const ApiResponseModel._();
factory ApiResponseModel({
@JsonKey(name: 'data') String? data,
}) = ResponseModel;
Id get id => Isar.autoIncrement;
factory ApiResponseModel.fromJson(Map<String, Object?> json) =>
_$ApiResponseModelFromJson(json);
}
Here is the error thrown while build_runner command.
Unsupported type. Please annotate the property with @ignore.
package:freezed_isar/api_response_model.freezed.dart:28:51
╷
28 │ $ApiResponseModelCopyWith<ApiResponseModel> get copyWith =>
│ ^^^^^^^^
╵
The type of copyWith
function generated by freezed
is not supported by isar
. To ignore copyWith
, you can use the @collection
annotation of isar like this:
@Collection(ignore: {'copyWith'})