1

I am try use SliverList for render data from backend (Firestore) in list. But I get error:

The following assertion was thrown building NotificationListener: Incorrect use of ParentDataWidget.

Flexible widgets must be placed inside Flex widgets. Flexible(no depth, flex: 1, dirty) has no Flex ancestor at all. The ownership chain for the parent of the offending Flexible was: RepaintBoundary ← IndexedSemantics ← NotificationListener ← KeepAlive ← AutomaticKeepAlive ← KeyedSubtree ← SliverList ← Viewport ← IgnorePointer-[GlobalKey#1e502] ← Semantics ← ⋯

          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,

But if I remove Flexible it give error:

The following assertion was thrown during performResize(): Vertical viewport was given unbounded height.

Viewports expand in the scrolling direction to fill their container.In this case, a vertical viewport was given an unlimited amount of vertical space in which to expand. This situation typically happens when a scrollable widget is nested inside another scrollable widget. If this widget is always nested in a scrollable widget there is no need to use a viewport because there will always be enough vertical space for the children. In this case, consider using a Column instead. Otherwise, consider using the "shrinkWrap" property (or a ShrinkWrappingViewport) to size the height of the viewport to the sum of the heights of its children. User-created ancestor of the error-causing widget was: FirestoreAnimatedList

If I replace FirestoreAnimatedlist with Placeholder() there is no problem:

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

How I can solve?

Thanks everyone!

FlutterFirebase
  • 2,163
  • 6
  • 28
  • 60

1 Answers1

0

Incorrect use of ParentDataWidget error in Flutter occurs when the Child widget has not matched the parent widget.

In your case, this error happens due to the Flexible() widget. It is not a descendant of a Flex widget:

 new CustomScrollView(
                  slivers: <Widget>[              
                    SliverList(
                      delegate: SliverChildListDelegate([
                       new Flexible(
                            child:
                            new FirestoreAnimatedList()
                               ...

To solve this error, your child widget must have the expected parent widget. Some of the widget and their parent widgets are:

Here Flexible is a descendant of Flex:

Flex(
  direction: Axis.horizontal,
  children: [
    Flexible(
      child: MyWidget(),
    ),
  ],
)

Row is also a Flex widget:

Row(
  children: [
    Expanded(
      child: MyWidget(),
    ),
  ],
)

And so is Column:

Column(
  children: [
    Flexible(
      child: MyWidget(),
    ),
  ],
)

Another option is to just get rid of the Flexible widget by wrapping your widget in a Container():

Container(
  child: MyWidget(),
)
MαπμQμαπkγVπ.0
  • 5,887
  • 1
  • 27
  • 65