Flutter 方法';fromjson';isn';t为类型';类型';
没有为类型“type”定义方法“fromJson”。Flutter 方法';fromjson';isn';t为类型';类型';,flutter,dart,retrofit,pojo,Flutter,Dart,Retrofit,Pojo,没有为类型“type”定义方法“fromJson”。 尝试将名称更正为现有方法的名称,或定义名为“fromJson”的方法 以下代码位于改装.g.dart文件中 @override Future<Map<String, dynamic>> signupCustomerRegistration(customerReg) async { ArgumentError.checkNotNull(customerReg, 'customerReg'); cons
尝试将名称更正为现有方法的名称,或定义名为“fromJson”的方法 以下代码位于改装.g.dart文件中
@override
Future<Map<String, dynamic>> signupCustomerRegistration(customerReg) async {
ArgumentError.checkNotNull(customerReg, 'customerReg');
const _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{};
final _data = <String, dynamic>{};
_data.addAll(customerReg?.toJson() ?? <String, dynamic>{});
final _result = await _dio.request<Map<String, dynamic>>(
'/api/API/CustomerSignUp',
queryParameters: queryParameters,
options: RequestOptions(
method: 'POST',
headers: <String, dynamic>{},
extra: _extra,
baseUrl: baseUrl),
data: _data);
var value = _result.data.map((k, dynamic v) =>
MapEntry(k, dynamic.fromJson(v as Map<String, dynamic>)));
return value;
}
@覆盖
未来注册CustomerRegistration(customerReg)异步{
ArgumentError.checkNotNull(customerReg,'customerReg');
const_extra={};
最终查询参数={};
最终_数据={};
_data.addAll(customerReg?.toJson()??{});
最终结果=等待请求(
“/api/api/CustomerSignUp”,
查询参数:查询参数,
选项:请求选项(
方法:“POST”,
标题:{},
额外的:_额外的,
baseUrl:baseUrl),
数据:_数据);
var值=_result.data.map((k,动态v)=>
MapEntry(k,dynamic.fromJson(v作为映射));
返回值;
}
我的型号文件代码如下所示:
// To parse this JSON data, do
//
// final customerReg = customerRegFromJson(jsonString);
import 'dart:convert';
import 'package:json_annotation/json_annotation.dart';
part 'CustomerRegModel.g.dart';
@JsonSerializable()
class CustomerRegModel {
CustomerRegModel({
this.custUid,
this.appname,
this.blacklist,
this.custEmail,
this.custName,
this.custPhone,
this.fcmToken,
this.password,
this.agentnin,
this.source,
this.signupDate,
this.commStartTime,
this.commEndTime,
this.commMaxValue,
this.commMinValue,
this.commDownValue,
this.walletamount,
});
String custUid;
String appname;
bool blacklist;
String custEmail;
String custName;
String custPhone;
String fcmToken;
String password;
String agentnin;
String source;
int signupDate;
int commStartTime;
int commEndTime;
int commMaxValue;
int commMinValue;
int commDownValue;
int walletamount;
factory CustomerRegModel.fromJson(Map<String, dynamic> json) => _$CustomerRegModelFromJson(json);
Map<String, dynamic> toJson() => _$CustomerRegModelToJson(this);
CustomerRegModel customerRegModelFromJson(String str) => CustomerRegModel.fromJson(json.decode(str));
String customerRegModelToJson(CustomerRegModel data) => json.encode(data.toJson());
}
//要解析此JSON数据,请执行以下操作
//
//最终customerReg=customerRegFromJson(jsonString);
导入“dart:convert”;
导入“package:json_annotation/json_annotation.dart”;
“CustomerRegModel.g.dart”部分;
@JsonSerializable()
类CustomerRegModel{
CustomerRegModel({
这个.custUid,
这个.appname,
这个黑名单,,
这是一封电子邮件,
这个名字,
这个电话,
这个.fcmToken,
这个密码,
这是阿根特宁,
这个消息来源,,
这个.signupDate,
这是一段时间,
这个时间,
这个.commMaxValue,
这个.commMinValue,
这个值,
这是walletamount,
});
字符串custUid;
字符串appname;
布尔黑名单;
字符串和电子邮件;
字符串名称;
电话线;
字符串fcmToken;
字符串密码;
字符串代理;
字符串源;
int-signupDate;
int通信开始时间;
起始时间;
int commMaxValue;
int commMinValue;
int值;
国际壁挂式;
factory CustomerRegModel.fromJson(映射json)=>\u$CustomerRegModelFromJson(json);
映射到JSON()=>$CustomerRegModelToJson(此);
CustomerRegModel customerRegModelFromJson(字符串str)=>CustomerRegModel.fromJson(json.decode(str));
字符串customerRegModelToJson(CustomerRegModel数据)=>json.encode(data.toJson());
}
已尝试:
- 使缓存无效并重新启动
- 删除.g.dart文件并重新创建它
- 已经为其他车型实施了相同的代码,并进行了改装,工作良好,只是没有在这方面工作
@GET("/api/API/CustomerLogin")
Future<String> loginCustomer(@Query('id') String email_or_number,
@Query('pass') String pass, @Query('check') String check);
@GET(“/api/api/CustomerLogin”)
未来登录客户(@Query('id')字符串电子邮件\u或\u编号,
@查询('pass')字符串传递,@Query('check')字符串检查);
请注意,上面我使用了字符串作为响应。现在我将使用json.decode方法将字符串转换为Map
final response = await client.loginCustomer(email_or_number,pass,check);
final Map<String,dynamic> map = json.decode(response);
final response=wait client.loginCustomer(电子邮件号码、密码、检查);
最终Map=json.decode(响应);
什么是动态.fromJson
?您不能像这样使用dynamic
。确切地说,请将dynamic.fromJson替换为CustomerRegModel.fromJsonIt正在使用用于改装的build runner命令创建自己