[英]Why im gettin this error RangeError (index): Invalid value: Valid value range is empty?
IM getting an error when using streambuilde and I cannot really figure out why. IM 在使用 streambuilde 时出现错误,我无法真正弄清楚原因。 heres the error这是错误
RangeError (index): Invalid value: Valid value range is empty: 0
The relevant error-causing widget was
StreamBuilder<QuerySnapshot>
lib/chatmessenger/recent_conversations_page.dart:49
And heres my code这是我的代码
@override
Widget build(BuildContext context) {
var firestore = FirebaseFirestore.instance;
return Container(
height: 50,
width: widget._width,
child: StreamBuilder<List<ConversationSnippet>>(
stream: DatbaseService.instance.getUserConversations(user.uid),
builder: (_context, _snapshot) {
var _data = _snapshot.data;
if (_data != null) {
_data.removeWhere((_c) {
return _c.timestamp == null;
});
if (_snapshot.data.isNotEmpty) {
return ListView.builder(
itemCount: _data.length,
itemBuilder: (_context, _index) {
return StreamBuilder(. here is the error thrownnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
stream: firestore
.collection('meinprofilsettings')
.where('uid', isEqualTo: _data[_index].uid)
.snapshots(),
builder: (context, snapshot) {
DocumentSnapshot video =
snapshot.data.docs[_index];
return ListTile(
onTap: () {
},
title: Text(video.data()['username']),
I marked in the code where the error is thrown and also you can see that I use the Documetnsnaoshot video in for the text in title.我在代码中标记了引发错误的位置,您还可以看到我使用了 Documetnsnaoshot 视频作为标题中的文本。 When im removing the Documetnsnapshot video the error is away.当我删除 Documetnsnapshot 视频时,错误消失了。 If you need more information please leave ac comment.如果您需要更多信息,请留下交流评论。 What I do is getting the data of streambuilder and then create inside this a new streambuikder where I fetch data from firebase with the uid.我所做的是获取streambuilder的数据,然后在其中创建一个新的streambuikder,我使用uid从firebase获取数据。 And last but not least I wanna display these data.最后但并非最不重要的一点是,我想显示这些数据。
So heres my firebase所以这是我的 firebase
And the doc id is the field _data[_index].uid.文档 id 是字段 _data[_index].uid。 So this works.but what I need instead of the field 'uid' is the doc id of the collection "meinprfosilsettings " Heres the picture所以这行得通。但是我需要的是集合“meinprfosilsettings”的文档ID而不是字段“uid”这是图片
IM getting an error when using streambuilde and I cannot really figure out why. IM 在使用 streambuilde 时出现错误,我无法真正弄清楚原因。 heres the error这是错误
RangeError (index): Invalid value: Valid value range is empty: 0
The relevant error-causing widget was
StreamBuilder<QuerySnapshot>
lib/chatmessenger/recent_conversations_page.dart:49
And heres my code这是我的代码
@override
Widget build(BuildContext context) {
var firestore = FirebaseFirestore.instance;
return Container(
height: 50,
width: widget._width,
child: StreamBuilder<List<ConversationSnippet>>(
stream: DatbaseService.instance.getUserConversations(user.uid),
builder: (_context, _snapshot) {
var _data = _snapshot.data;
if (_data != null) {
_data.removeWhere((_c) {
return _c.timestamp == null;
});
if (_snapshot.data.isNotEmpty) {
return ListView.builder(
itemCount: _data.length,
itemBuilder: (_context, _index) {
return StreamBuilder(. here is the error thrownnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
stream: firestore
.collection('meinprofilsettings')
.where('uid', isEqualTo: _data[_index].uid)
.snapshots(),
builder: (context, snapshot) {
DocumentSnapshot video =
snapshot.data.docs[_index];
return ListTile(
onTap: () {
},
title: Text(video.data()['username']),
I marked in the code where the error is thrown and also you can see that I use the Documetnsnaoshot video in for the text in title.我在代码中标记了引发错误的位置,您还可以看到我使用了 Documetnsnaoshot 视频作为标题中的文本。 When im removing the Documetnsnapshot video the error is away.当我删除 Documetnsnapshot 视频时,错误消失了。 If you need more information please leave ac comment.如果您需要更多信息,请留下交流评论。 What I do is getting the data of streambuilder and then create inside this a new streambuikder where I fetch data from firebase with the uid.我所做的是获取streambuilder的数据,然后在其中创建一个新的streambuikder,我使用uid从firebase获取数据。 And last but not least I wanna display these data.最后但并非最不重要的一点是,我想显示这些数据。
So heres my firebase所以这是我的 firebase
And the doc id is the field _data[_index].uid.文档 id 是字段 _data[_index].uid。 So this works.but what I need instead of the field 'uid' is the doc id of the collection "meinprfosilsettings " Heres the picture所以这行得通。但是我需要的是集合“meinprfosilsettings”的文档ID而不是字段“uid”这是图片
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.