当前位置:网站首页>flutter 服务器返回数据判断是否为空
flutter 服务器返回数据判断是否为空
2022-08-05 10:40:00 【氤氲息】
一般的数据,可以为null
列表就可以为null或者是[]
1.先判断那一整块数据是否为null
2.判断数据里面的list是否为null,还是返回[]
可以用result != null && result.isNotEmpty(result.length!=0)作判断,如果为空就显示缺省图或者不让它显示
3.之后就是那一整块数据里面的各个小数据,都要判断一下,如果为null就用a??0,默认显示0
{
"data": {
"list": {
"user_id": 0,
"rich_value": "string",
"nickname": "string",
"avatar": "string",
"sex": 0,
"age": 0,
"rank": 0
}
},
"code": 0,
"msg": "string"
}
如下,如果想正确的获取到头像的值,防止为空,可一层层判断是否为空,如果为空就显示默认值
String getAvatar(index) {
String avatar = "";//先设置一个默认的头像地址
if (richRankList != null) {
//如果服务器直接返回null
if (richRankList!.rankList != null&&richRankList!.rankList!.isNotEmpty) {
//如果列表为null,或者返回[](即空数据)
if (richRankList!.rankList![index].avatar != null) {
//如果头像地址不为null
avatar = richRankList!.rankList![index].avatar!;//那就正常赋值
}
}
}
return avatar;//返回头像值
}
边栏推荐
- three物体围绕一周呈球形排列
- Is digital transformation a business buy-in?
- Chapter 5: Multithreaded Communication—wait and notify
- 【Office】Microsoft Office下载地址合集(微软官方原版离线安装下载)
- 反射修改jsessionid实现Session共享
- MySQL transactions
- High-quality DeFi application building guide to help developers enjoy DeFi Summer
- 如何选币与确定对应策略研究
- 这份阿里强推的并发编程知识点笔记,将是你拿大厂offer的突破口
- 第五章:redis持久化,包括rdb和aof两种方式[通俗易懂]
猜你喜欢
Leetcode刷题——623. 在二叉树中增加一行
【OpenCV】-仿射变换
SQL Outer Join Intersection, Union, Difference Query
JS introduction to reverse the recycling business network of learning, simple encryption mobile phone number
The JVM collection that Alibaba's top architects have summarized for many years, where can't I check it!
【加密解密】明文加密解密-已实现【已应用】
这份阿里强推的并发编程知识点笔记,将是你拿大厂offer的突破口
E-sports, convenience, efficiency, security, key words for OriginOS functions
数据可视化(一)
今天告诉你界面控件DevExpress WinForms为何弃用经典视觉样式
随机推荐
How to choose coins and determine the corresponding strategy research
MySQL data view
RT - Thread record (a, RT, RT Thread version - Thread Studio development environment and cooperate CubeMX quick-and-dirty)
Common operations of oracle under linux and daily accumulation of knowledge points (functions, timed tasks)
Complete image segmentation efficiently based on MindSpore and realize Dice!
2022杭电多校 第6场 1008.Shinobu Loves Segment Tree 规律题
Introduction to SD NAND Flash!
012年通过修补_sss_提高扩散模型效率
js hijacks the array push method
Where is your most secretive personality?
第四章:activiti RuntimeService设置获和取流程变量,及与taskService的区别,开始和完成任务时设置流程变量[通俗易懂]
Our Web3 Entrepreneurship Project, Yellow
2022技能大赛训练题:交换机snmp配置
How does the official account operate and maintain?Public account operation and maintenance professional team
智能算力的枢纽如何构建?中国云都的淮海智算中心打了个样
[Android] How to use RecycleView in Kotlin project
【OpenCV】-仿射变换
sqlserver编写通用脚本实现获取一年前日期的方法
华为轻量级神经网络架构GhostNet再升级,GPU上大显身手的G-GhostNet(IJCV22)
Login function and logout function (St. Regis Takeaway)