我正在尝试从 firebase firestore 获取帖子,我已经这样做了,但是当我尝试在网格和列表视图中显示获取的数据时。网格视图有效,但是当我按下列表图标以查看列表形式的已获取帖子时,我收到此错误。
Failed assertion: line 4269 pos 14: 'owner!._debugCurrentBuildTarget == this': is not true.
The getter 'key' was called on null.
Receiver: null
Tried calling: key
'package:flutter/src/widgets/framework.dart': Failed assertion: line 5170 pos 14: '() {
// check that it really is our descendant
Element? ancestor = dependent._parent;
while (ancestor != this && ancestor != null)
ancestor = ancestor._parent;
return ancestor == this;
}()': is not true.
type 'int' is not a subtype of type 'Map<dynamic, dynamic>'
Failed assertion: line 258 pos 16: 'child == null || indexOf(child) > index': is not true.
A RenderSliverPadding expected a child of type RenderSliver but received a child of type RenderErrorBox
.
我从 Firestore 中获取了如下所示的帖子数据,它可以工作,并且数据以网格形式显示,但是当我尝试以列表形式显示时发生错误
void getAllProfilePost()async {
setState(() {
loading=true;
});
QuerySnapshot querySnapshot=
await PostReference.doc(profileUserID).collection('userspost').orderBy('timeStamp',descending: true).get();
countPost= querySnapshot.docs.length;
setState(() {
loading=false;
countPost= querySnapshot.docs.length;
PostList= querySnapshot.docs.map((documentSnapshot) => Post.fromDocument(documentSnapshot)).toList();
});
}
这里我创建了两个图标列表和网格来以两种格式显示获取的帖子数据,网格视图工作但我在列表视图中遇到错误
这里是我如何在网格中显示获取的帖子,它工作正常
if(postOrientation=="grid"){
List<GridTile>gridTleslist=[];
PostList.forEach((eachPost) {
gridTleslist.add(GridTile(child: PostTile(eachPost)));
});
return GridView.count(
crossAxisCount: 3,
childAspectRatio: 1.0,
mainAxisSpacing: 1.5,
crossAxisSpacing: 1.5,
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
children: gridTleslist,
);
}
这是我尝试以列表格式显示 Fteched 帖子的方式,此处发生错误
if(postOrientation=="list"){
return Column(
children: PostList,
);
}
Failed assertion: line 258 pos 16: 'child == null || indexOf(child) > index': is not true.
'package:flutter/src/rendering/sliver_multi_box_adaptor.dart': Failed assertion: line 258 pos 16: 'child == null || indexOf(child) > index': is not true.
Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
https://github.com/flutter/flutter/issues/new?template=2_bug.md
The relevant error-causing widget was:
ListView file:///C:/Users/likec/OneDrive/Desktop/project%20file/nethouese/lib/pages/imported/pages/ProfilePage.dart:40:14
When the exception was thrown, this was the stack:
#2 RenderSliverMultiBoxAdaptor._debugVerifyChildOrder (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:258:16)
#3 RenderSliverMultiBoxAdaptor.debugChildIntegrityEnabled=.<anonymous closure> (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:233:14)
#4 RenderSliverMultiBoxAdaptor.debugChildIntegrityEnabled= (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:235:6)
#5 SliverMultiBoxAdaptorElement.performRebuild (package:flutter/src/widgets/sliver.dart:1208:20)
#6 SliverMultiBoxAdaptorElement.update (package:flutter/src/widgets/sliver.dart:1124:7)