如何解决未为 Dart 中的类型定义 getter 'fromJson'
我正在学习 flutter,尝试使用 Getx 的 GetConnect Custom configuration,
当尝试为默认请求设置 defaultDecoder 时,它抱怨:
The getter 'fromJson' isn't defined for the type 'Resp'.
Try importing the library that defines 'fromJson',correcting the name to the name of an existing getter,or defining a getter or field named 'fromJson'.dart"
如何修复这个错误?
这是我的代码:
import 'package:get/get.dart';
class AuthService extends GetConnect {
@override
void onInit() {
// All request will pass to jsonEncode so CasesModel.fromJson()
httpClient.defaultDecoder = Resp.fromJson;
httpClient.baseUrl = 'http://localhost/app_api/auth';
}
Future<Response<Map<String,dynamic>>> getCaptcha(String mobile) =>
get("get_captcha");
}
class Resp {
final int Errcode;
final String Errmsg;
final Map<String,dynamic> Data;
Resp(this.Errcode,this.Errmsg,this.Data);
factory Resp.fromJson(Map<String,dynamic> json) {
return Resp(json["errcode"],json["errmsg"],json["data"]);
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。