1

我尝试使用SliverList列表中来自后端(Firestore)的渲染数据。但我得到错误:

在构建 NotificationListener 时引发了以下断言:ParentDataWidget 的使用不正确。

灵活的小部件必须放在 Flex 小部件内。Flexible(no depth, flex: 1, dirty) 根本没有 Flex 祖先。违规 Flexible 的父级的所有权链是:RepaintBoundary ← IndexedSemantics ← NotificationListener ← KeepAlive ← AutomaticKeepAlive ← KeyedSubtree ← SliverList ← Viewport ← IgnorePointer-[GlobalKey#1e502] ← Semantics ←⋯</p>

          new CustomScrollView(
                  slivers: <Widget>[              
                    SliverList(
                      delegate: SliverChildListDelegate([
                       new Flexible(
                            child:
                            new FirestoreAnimatedList(
                              query: reference
                                  .orderBy('timestamp', descending: true)
                                  .snapshots(),
                              itemBuilder: (_, DocumentSnapshot snapshot,
                                  Animation<double> animation) {
                                return new Widget(
                                  snapshot: snapshot,
                                  animation: animation,

但是,如果我将其删除Flexible,则会出现错误:

在 performResize() 期间引发了以下断言:垂直视口被赋予了无限的高度。

视口在滚动方向上扩展以填充其容器。在这种情况下,垂直视口被赋予了无限量的垂直空间来扩展。当可滚动小部件嵌套在另一个可滚动小部件中时,通常会发生这种情况。如果此小部件始终嵌套在可滚动小部件中,则无需使用视口,因为总会有足够的垂直空间供子项使用。在这种情况下,请考虑改用 Column。否则,请考虑使用“shrinkWrap”属性(或 ShrinkWrappingViewport)将视口的高度调整为其子项高度的总和。导致错误的小部件的用户创建的祖先是:FirestoreAnimatedList

如果我替换FirestoreAnimatedlistPlaceholder()没有问题:

          new CustomScrollView(
                  slivers: <Widget>[              
                    SliverList(
                      delegate: SliverChildListDelegate([
                        Placeholder(),
        Placeholder(),
        Placeholder(),

我该如何解决?

感谢大家!

4

0 回答 0