I'm using Freezed
to generate data-class on my flutter project.
I did everything exactly like mentioned in the package readme:
import 'package:freezed_annotation/freezed_annotation.dart';
part 'access_token.freezed.dart';
@freezed
class AccessToken with _$AccessToken {
@JsonSerializable()
const factory AccessToken(
@JsonKey(name: 'access_token') String accessToken,
@JsonKey(name: 'refresh_token') String refreshToken,
) = _AccessToken;
factory AccessToken.fromJson(Map<String, Object?> json) =>
_$AccessTokenFromJson(json);
}
The build completes successfully.
When I run the app I'm getting:
lib/services/models/access_token.freezed.dart:118:7: Error: Method not found: '_$$_AccessTokenFromJson'. _$$AccessTokenFromJson(json); ^^^^^^^^^^^^^^^^^^^^^^^ lib/services/models/access_token.freezed.dart:157:12: Error: The method '$$AccessTokenToJson' isn't defined for the class '$_AccessToken'.
- '_$AccessToken' is from 'package:tenant_app/services/models/access_token.dart' ('lib/services/models/access_token.dart'). Try correcting the name to the name of an existing method, or defining a method named '$$_AccessTokenToJson'. return _$$_AccessTokenToJson(
Why Freezed
didn't generate that function correctly? What am I missing?
json_annotation
andjson_serializable
to my project dependences. – Fleisig