Open BhavinMCT opened 4 years ago
Looks like your api response have an Int in status key
status:1
Try to change the data type of status from String to Int in WrappedResponse
@ydhnwb thanks for your input but your suggestion want work , same error pops up. One thing I want to say is I created new project and code everything manually instead of json_serializable it will convert all json data into model class , So my thinking is to auto generated code not generated properly.
Hello @ydhnwb, After updating flutter I'll getting error in this file
import 'dart:io';
import 'dart:math';
import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_demo/converters/wrapped_response.dart';
import 'package:flutter_demo/models/User.dart';
import 'package:flutter_demo/models/UserHeadar.dart';
import 'package:retrofit/retrofit.dart';
part 'api_service.g.dart';
@RestApi(baseUrl: "https://telefitapp.com/telefit_dev/api/v1/")
abstract class RestClient {
factory RestClient(Dio dio) = _RestClient;
@POST("login")
Future<WrappedResponse> login(@Field("email") String email,@Field("password") String password,@Field("device_type") String type,@Field("device_token") String token);
}
WrappedResponse class
import 'package:flutter_demo/models/User.dart';
import 'package:json_annotation/json_annotation.dart';
part 'wrapped_response.g.dart';
@JsonSerializable()
class WrappedResponse{
@JsonKey(name: "message")
String message;
@JsonKey(name: "status")
int status;
@JsonKey(name: "result")
User data;
WrappedResponse(this.message, this.status, this.data);
factory WrappedResponse.fromJson(Map<String, dynamic> json) => _$WrappedResponseFromJson(json);
Map<String, dynamic> toJson() => _$WrappedResponseToJson(this);
}
Error on command "flutter packages pub run build_runner build --delete-conflicting-outputs"
[SEVERE] retrofit_generator:retrofit on lib/webservices/api_service.dart (cached):
Could not format because the source could not be parsed:
line 16, column 31: Expected an identifier.
╷
16 │ final value = WrappedResponse*.fromJson(_result.data);
│ ^
╵
[SEVERE] Failed after 933ms
pub finished with exit code 1
I am new in flutter and I am not able to solve this issue can anyone help me? I am able to get data in string if I type
Future<String> login()
instead ofFuture<WrappedResponse> login()
this and it will print on Presenter class which is given below.This is my api class
This is my wrapper class
This is my user class
This is my Presenter class
And my response is