flutter 1.升级2.X在模型类中序列化JSON报错

Non-nullable instance field 'title' must be initialized.
Try adding an initializer expression,
or add a field initializer in this constructor, or mark it 'late'.

修改方案--添加late



原有代码

class Autogenerated {
List<Result> result; Autogenerated({this.result}); Autogenerated.fromJson(Map<String, dynamic> json) {
if (json['result'] != null) {
result = new List<Result>();
json['result'].forEach((v) {
result.add(new Result.fromJson(v));
});
}
} Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
if (this.result != null) {
data['result'] = this.result.map((v) => v.toJson()).toList();
}
return data;
}
} class Result {
String sId;
String title;
String status;
String pic;
String url; Result({this.sId, this.title, this.status, this.pic, this.url}); Result.fromJson(Map<String, dynamic> json) {
sId = json['_id'];
title = json['title'];
status = json['status'];
pic = json['pic'];
url = json['url'];
} Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['_id'] = this.sId;
data['title'] = this.title;
data['status'] = this.status;
data['pic'] = this.pic;
data['url'] = this.url;
return data;
}
}

修改后的

class Autogenerated {
late List<Result> result; Autogenerated({required this.result}); Autogenerated.fromJson(Map<String, dynamic> json) {
if (json['result'] != null) {
result = [];
json['result'].forEach((v) {
result.add(new Result.fromJson(v));
});
}
} Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
if (this.result != null) {
data['result'] = this.result.map((v) => v.toJson()).toList();
}
return data;
}
} class Result {
late String sId;
late String title;
late String status;
late String pic;
late String url; Result(
{required this.sId,
required this.title,
required this.status,
required this.pic,
required this.url}); Result.fromJson(Map<String, dynamic> json) {
sId = json['_id'];
title = json['title'];
status = json['status'];
pic = json['pic'];
url = json['url'];
} Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['_id'] = this.sId;
data['title'] = this.title;
data['status'] = this.status;
data['pic'] = this.pic;
data['url'] = this.url;
return data;
}
}

flutter 1.升级2.X在模型类中序列化JSON报错Non-nullable instance field 'title' must be initialized.的更多相关文章

  1. .net winform 调用类中的webbrowser 报错:当前线程不在单线程单元中,因此无法实例化 ActiveX

    遇到这个恶心的问题纠缠得不要不要的,大家遇到了的话希望不要走弯路,经过这个折腾让我有点怀疑人生了.哈哈哈 解决代码如下: //插入一个新线程用于处理验证码 Thread thd = new Threa ...

  2. python---Django中模型类中Meta元对象了解

    Django中模型类中Meta元对象了解 1.使用python manage.py shell 进入编辑命令行模式,可以直接进入项目(为我们配置好了环境) python manage.py shell ...

  3. linux下启动dbca或netmgr类的图形界面报错解决

    linux下启动dbca或netmgr类的图形界面报错解决    Xlib: connection to ":0.0" refused by server Xlib: No pro ...

  4. Spring MVC普通类或工具类中调用service报空空指针的解决办法(调用service报java.lang.NullPointerException)

    当我们在非Controller类中应用service的方法是会报空指针,如图: 这是因为Spring MVC普通类或工具类中调用service报空null的解决办法(调用service报java.la ...

  5. Springboot实体类转JSON报错Could not find acceptable representation & 设置访问项目根路径的默认欢迎页面

    =================实体类转JSON报错的解决办法============= 之前在springmvc的时候也报过这个错,原因以及springmvc中解决办法参考:https://www ...

  6. 将Xcode升级到10.0以上版本,Appium启动报错的问题

    前言 现在的Xcode最新版本都是在10.1,原先使用的版本是9.4.1!结果今天手贱将其升级... 然后,跑IOS自动化时,出现“Xcode version '0.1'. Support for X ...

  7. idea生成类中序列化id

    RPC接口中要传输的对象需要序列化,需要生成序列id,idea中生成序列id的方式如下 在需要添加序列id的类中,选中类名,alt+enter就可以实现了

  8. 处理flutter http请求添加application/json报错Cannot set the body fields of a Request with content-type “application/json”

    在flutter中在http请求发送时设置"content-type": "application/json"会出现报错Cannot set the body ...

  9. moviepy音视频剪辑VideoClip类fl_image方法image_func报错ValueError: assignment destination is read-only解决办法

    ☞ ░ 前往老猿Python博文目录 ░ moviepy音视频剪辑模块的视频剪辑基类VideoClip的fl_image方法用于进行对剪辑帧数据进行变换. 调用语法:fl_image(self, im ...

随机推荐

  1. Elasticsearch Analyzer 内置分词器

    Elasticsearch Analyzer 内置分词器 篇主要介绍一下 Elasticsearch中 Analyzer 分词器的构成 和一些Es中内置的分词器 以及如何使用它们 前置知识 es 提供 ...

  2. Codeforces Round #805 (Div. 3)E.Split Into Two Sets

    题目链接:https://codeforces.ml/contest/1702/problem/E 题目大意: 每张牌上面有两个数字,现在有n张牌(n为偶数),问能否将这n张牌分成两堆,使得每堆牌中的 ...

  3. JAVA-注解之 TODO、FIXME、XXX

    TODO.FIXME.XXX    //TODO : 表示待实现的功能    //FIXME: 代码存在Bug,不能Run或运行结果不正确,需要修复    //XXX  : 勉强可以工作,但是实现的方 ...

  4. 视频服务HDR Vivid 还原色彩,让所见成“真”

    如今,视频正在以一种前所未有的方式渗入日常生活,是当下人们记录生活最热门的方式.所以,用户对视频的画质要求越来越高,App想要吸引更多的用户,拥有视频画质新技术的强力支撑很关键. HDR(High-D ...

  5. mindxdl--common--http_handler.go

    // Copyright (c) 2021. Huawei Technologies Co., Ltd. All rights reserved.// Package common this file ...

  6. i春秋wanna to see your hat?

    打开题目网页发现是个选择帽子的网页,点击超链接进入一个网页让我们输入我们的name然后匹配帽子颜色(其实不管怎么填都是绿色的)这里也有个注册窗口 先查看源码没什么特别发现,再试试抓包吧 在这个界面抓包 ...

  7. NavBarControl 通过代码添加

    看到网上很多都是直接在控件上面添加的 而我的是保存在数据库读取后添加的. 后来自己摸索了一下. 通过代码添加 navBarControl1.Groups.Add(new NavBarGroup( st ...

  8. CLion和动态链接库

    目录 生成链接库 链接库的使用 生成链接库 创建一个library项目 在项目中写好自己的代码 cmakelist cmake_minimum_required(VERSION 3.21) proje ...

  9. 5V降压转3.3V,5V转3V电路图芯片

    5V降压转3.3V和3V都是低压,两个之间的压差效率,所以效率和工作温度这块都会比较优秀,输入和输出的最低压差外是越小越好. 1, 如果电流比较小,可以用LDO: PW6566 系列是使用 CMOS ...

  10. Springboot配置多Redis源

    Springboot配置多Redis源 一.背景 因项目部署了新集群,某些缓存数据需要在旧的redis上取,就必须配置多个数据源动态获取相对应的源以兼容业务. 二.配置依赖 <dependenc ...