当前位置:网站首页>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;//返回头像值
}
边栏推荐
- 第六章:activiti流程分流判断之排它网关和并行网关
- In-depth understanding of timeout settings for Istio traffic management
- The century-old Nordic luxury home appliance brand ASKO smart wine cabinet in the three-temperature area presents the Chinese Valentine’s Day, and tastes the love of the delicacy
- FPGA: Basic Getting Started LED Lights Blinking
- nyoj754 黑心医生 结构体优先队列
- 企业的数字化转型到底是否可以买来?
- 这份阿里强推的并发编程知识点笔记,将是你拿大厂offer的突破口
- 【综合类型第 35 篇】程序员的七夕浪漫时刻
- What is SPL?
- abc262-D(dp)
猜你喜欢

SQL Outer Join Intersection, Union, Difference Query

FPGA:开发环境Vivado的使用

这份阿里强推的并发编程知识点笔记,将是你拿大厂offer的突破口

Opencv算术操作

DocuWare平台——文档管理的内容服务和工作流自动化的平台详细介绍(下)

This notebook of concurrent programming knowledge points strongly recommended by Ali will be a breakthrough for you to get an offer from a big factory

上位机开发C#语言:模拟STC串口助手接收单片机发送数据

60行从零开始自己动手写FutureTask是什么体验?

three objects are arranged in a spherical shape around the circumference

Data Middle Office Construction (10): Data Security Management
随机推荐
攻防世界-PWN-new_easypwn
数据可视化(二)
Complete image segmentation efficiently based on MindSpore and realize Dice!
FPGA: Use of the development environment Vivado
This notebook of concurrent programming knowledge points strongly recommended by Ali will be a breakthrough for you to get an offer from a big factory
登录功能和退出功能(瑞吉外卖)
The founder of the DFINITY Foundation talks about the ups and downs of the bear market, and where should DeFi projects go?
【C语言指针】用指针提升数组的运算效率
nyoj86 找球号(一) set容器和二分 两种解法
012_SSS_ Improving Diffusion Model Efficiency Through Patching
MySQL事务
Huawei's lightweight neural network architecture GhostNet has been upgraded again, and G-GhostNet (IJCV22) has shown its talents on the GPU
PCB layout must know: teach you to correctly lay out the circuit board of the op amp
产品太多了,如何实现一次登录多产品互通?
[Android]如何使用RecycleView in Kotlin project
R语言使用yardstick包的pr_curve函数评估多分类(Multiclass)模型的性能、查看模型在多分类每个分类上的ROC曲线(precision(精准率),R代表的是recall(召回率)
牛刀小试基本语法,Go lang1.18入门精炼教程,由白丁入鸿儒,go lang基本语法和变量的使用EP02
这份阿里强推的并发编程知识点笔记,将是你拿大厂offer的突破口
深入理解 Istio 流量管理的超时时间设置
js hijacks the array push method