flutter - Flutter 中的值不在范围 1 内
问题描述
我正在尝试使用列表视图列出我从 firebase 获取的数据,如您在此处看到的
Widget chatRoomsList() {
return StreamBuilder(
stream: chatRooms,
builder: (context, snapshot) {
return snapshot.hasData
? ListView.builder(
itemCount: snapshot.data.documents.length,
shrinkWrap: true,
itemBuilder: (context, index) {
return ChatRoomsTile(
userName: snapshot.data.documents[index].data['chatRoomId']
.toString()
.replaceAll("_", "")
.replaceAll(Constants.myName, ""),
chatRoomId:
snapshot.data.documents[index].data["chatRoomId"],
);
})
: Container();
},
);
}
但是,当我列出出现错误的项目时,您可以在此处看到:
════════ Exception caught by widgets library ═══════════════════════════════════
The following RangeError was thrown building ChatRoomsTile(dirty):
Value not in range: 1
The relevant error-causing widget was
ChatRoomsTile
package:charlotapp/…/chat/chat_room.dart:29
When the exception was thrown, this was the stack
#0 _StringBase.substring (dart:core-patch/string_patch.dart:399:7)
#1 ChatRoomsTile.build
package:charlotapp/…/chat/chat_room.dart:147
#2 StatelessElement.build
package:flutter/…/widgets/framework.dart:4641
#3 ComponentElement.performRebuild
package:flutter/…/widgets/framework.dart:4567
#4 Element.rebuild
package:flutter/…/widgets/framework.dart:4261
知道为什么会这样吗?
解决方案
推荐阅读
- javascript - 具体如何打印使用 javascript 或 jquery 在新窗口中显示内容?
- laravel - API端点身份验证后在laravel应用程序中登录用户
- android - setIsSmartLockEnabled(false) 在 FirebaseUI Lib 中不起作用
- python - Python - 用指数函数拟合数据
- python - Python:遍历多个字典中的文件
- spring - Keycloak configuration in application.properties for spring boot
- excel - 如何在有动态输入和动态输出的地方重复“替换”命令?
- spring - JHipster/LDAP - 在第一次连接时在 JHipster BDD 中创建新用户
- python - 使用 MMA8451 加速度计和 Rpi 进行运动检测,我是否正确读取和写入寄存器?
- git - VS 代码:有没有办法忽略 git 中的文件?