-
Notifications
You must be signed in to change notification settings - Fork 251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
toJson will not add if we use freezed. #682
Comments
.g.dart
in analysis_options
Temporary solution. |
Duplicate.
|
Not working in env flutter 3.24 The generated retrofit class didn't auto insert
part 'auth_client.g.dart';
@RestApi()
abstract class AuthClient {
factory AuthClient(Dio dio, {required String baseUrl}) = _AuthClient;
@POST("/members/login")
Future<ApiResponse<LoginResponse?>> login(@Body() LoginBody body);
}
@override
Future<ApiResponse<LoginResponse?>> login(LoginBody body) async {
final _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{};
final _headers = <String, dynamic>{};
/// toJson() is missing here
final _data = body;
final _result = await _dio.fetch<Map<String, dynamic>>(
_setStreamType<ApiResponse<LoginResponse>>(Options(
method: 'POST',
headers: _headers,
extra: _extra,
)
part 'login_body.freezed.dart';
part 'login_body.g.dart';
@Freezed()
sealed class LoginBody with _$LoginBody {
const factory LoginBody({
@JsonKey(name: "phone_no") String? phoneNo,
String? password,
String? email,
String? otp,
@JsonKey(name: "login_method")
@Default(LoginMethod.phonePassword)
LoginMethod loginMethod,
}) = _LoginBody;
factory LoginBody.fromJson(Map<String, dynamic> json) =>
_$LoginBodyFromJson(json);
} |
This worked for me but it'd be good to not have to do this to make the generator happy |
@lailai0715 , did you find a solution? I have the same problem |
follow the temporary solution provided by @nicolasWenia , it's working in my project Packages version used: |
Describe the bug
toJson will not add if we use freezed.
and show this warning
To Reproduce
Steps to reproduce the behavior:
Expected behavior
If body is not Map force to add toJson() whether it has toJson() or not.
The text was updated successfully, but these errors were encountered: