flutter - 在 null 上调用了 getter 'isNotEmpty'。接收方:null 尝试调用:isNotEmpty
问题描述
Widget _profileInfo(Users profileData) {
return Padding(
padding: const EdgeInsets.all(15.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
CircleAvatar(
backgroundColor: Colors.grey,
radius: 50.0,
backgroundImage: profileData.photoUrl.isNotEmpty
? NetworkImage(profileData.photoUrl)
: AssetImage("images/user.png"),
)
],
),
SizedBox(
height: 10.0,
),
Text(
profileData.userName,
style: TextStyle(fontSize: 15.0, fontWeight: FontWeight.bold),
),
SizedBox(
height: 10.0,
),
_profileEditButton(),
SizedBox(
height: 10.0,
),
_logoutButton(),
],
),
);
}
解决方案
profileData.photoUrl.isNotEmpty
需要是
profileData?.photoUrl?.isNotEmpty ?? false
所以它将默认为false
ifprofileData
或profileData.photoUrl
not 设置。
推荐阅读
- ssl - 本地主机的主题备用名称
- java - 在java中螺旋打印矩阵
- javascript - 从 metaweather API 获取数据以响应页面
- go - Go 支持函数式编程吗?
- javascript - 谷歌分析是否也适用于 react-router-dom?
- typescript - 导出 * 与命名导出在模块增强方面有所不同
- python - Selenium move_to_element 在循环中移动所有元素
- ffmpeg - ffmpeg。缩放时不保留透明度
- .net-core - ibmcloud 功能,(openwhisk).cant 使用 net core 3.1 连接到 redis 无法加载文件或程序集“System.IO.Pipelines”
- json - 如何 PUT 到 JSON 字符串 REST-API 中数组的特定索引?