flutter - snapshotData.docs[index].data()['firstName'] 出现错误
问题描述
- 我正在尝试
Searchbar
为我的应用程序实现,它将根据用户的firstName
. - 我面临以下错误说
The method '[]' can't be unconditionally invoked because the receiver can be 'null'.
Try making the call conditional (using '?.') or adding a null check to the target ('!').
- 代码
late QuerySnapshot snapshotData;
..
..
title: Text(snapshotData.docs[index].data()['firstName'], style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 24.0
),
),
解决方案
利用
Text(snapshotData.docs[index].get('firstName'))
推荐阅读
- mysql - 我们如何使用 vue js 从数据库中检索产品数量?
- javascript - Javascript Canvas 渲染方法在 IE11 中不起作用
- javascript - 意外的令牌错误:React js 页面未加载
- php - 如果数组是多维的,如何按第一个值对数组进行排序?
- reactjs - 你应该总是同时使用 Redux 和 REST API 吗?
- mongodb - 未处理的承诺拒绝错误:“请求失败,状态码 400”
- javascript - 有效性.valid 是如何工作的?
- pip - 使用 pip install 安装 Cartopy 但缺少 Proj 版本至少 4.9.0
- java - SOAP Web 服务 - 无法从 XSD 生成类
- rust - 可变借用固定结构的两个字段