Flutter 颤振时阀不在范围1内
我正在尝试使用listview列出我从firebase获得的数据,正如您在这里看到的Flutter 颤振时阀不在范围1内,flutter,listview,Flutter,Listview,我正在尝试使用listview列出我从firebase获得的数据,正如您在这里看到的 Widget chatRoomsList() { return StreamBuilder( stream: chatRooms, builder: (context, snapshot) { return snapshot.hasData ? ListView.builder( itemCount: s
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
知道为什么会这样吗