robert-luoqing / flutter_list_view

MIT License
45 stars 17 forks source link

Assertion 'child.parent == this': is not true #13

Closed Iridescentangle closed 2 years ago

Iridescentangle commented 2 years ago

尝试在项目中引入flutter_list_view用来展示消息列表,展示正常,但是下拉加载历史消息时(因为消息列表是反转的)抛出异常

======== Exception caught by rendering library =====================================================
The following assertion was thrown during performLayout():
RenderBox.size accessed beyond the scope of resize, layout, or permitted parent access. RenderBox can always access its own size, otherwise, the only object that is allowed to read RenderBox.size is its parent, if they have said they will. It you hit this assert trying to access a child's size, pass "parentUsesSize: true" to that child's layout().
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1938 pos 13: 'debugDoingThisResize || debugDoingThisLayout || _computingThisDryLayout ||
              (RenderObject.debugActiveLayout == parent && _size._canBeUsedByParent)'

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: 
  FlutterSliverList file:///Users/xx/Documents/workspace/xx/flutter_list_view/lib/src/flutter_list_view.dart:161:7
When the exception was thrown, this was the stack: 
#2      RenderBox.size.<anonymous closure> (package:flutter/src/rendering/box.dart:1938:13)
#3      RenderBox.size (package:flutter/src/rendering/box.dart:1951:6)
#4      FlutterListViewRender.performLayout (package:flutter_list_view/src/flutter_list_view_render.dart:213:30)
#5      RenderObject.layout (package:flutter/src/rendering/object.dart:1779:7)
#6      RenderViewportBase.layoutChildSequence (package:flutter/src/rendering/viewport.dart:510:13)
...
The following RenderObject was being processed when the exception was fired: FlutterListViewRender#7574b relayoutBoundary=up1 NEEDS-LAYOUT NEEDS-COMPOSITING-BITS-UPDATE
...  needs compositing
...  parentData: paintOffset=Offset(0.0, 0.0) (can use size)
...  constraints: SliverConstraints(AxisDirection.up, GrowthDirection.forward, ScrollDirection.reverse, scrollOffset: 825.5, remainingPaintExtent: 718.0, crossAxisExtent: 432.0, crossAxisDirection: AxisDirection.right, viewportMainAxisExtent: 718.0, remainingCacheExtent: 1218.0, cacheOrigin: -250.0)
...  geometry: SliverGeometry(scrollExtent: 1922.1, paintExtent: 718.0, maxPaintExtent: 718.0, hasVisualOverflow: true, cacheExtent: 1218.0)
...    scrollExtent: 1922.1
...    paintExtent: 718.0
...    maxPaintExtent: 718.0
...    hasVisualOverflow: true
...    cacheExtent: 1218.0
RenderObject: FlutterListViewRender#7574b relayoutBoundary=up1 NEEDS-LAYOUT NEEDS-COMPOSITING-BITS-UPDATE
  needs compositing
  parentData: paintOffset=Offset(0.0, 0.0) (can use size)
  constraints: SliverConstraints(AxisDirection.up, GrowthDirection.forward, ScrollDirection.reverse, scrollOffset: 825.5, remainingPaintExtent: 718.0, crossAxisExtent: 432.0, crossAxisDirection: AxisDirection.right, viewportMainAxisExtent: 718.0, remainingCacheExtent: 1218.0, cacheOrigin: -250.0)
  geometry: SliverGeometry(scrollExtent: 1922.1, paintExtent: 718.0, maxPaintExtent: 718.0, hasVisualOverflow: true, cacheExtent: 1218.0)
    scrollExtent: 1922.1
    paintExtent: 718.0
    maxPaintExtent: 718.0
    hasVisualOverflow: true
    cacheExtent: 1218.0
====================================================================================================

======== Exception caught by rendering library =====================================================
The following assertion was thrown during paint():
'package:flutter_list_view/src/flutter_list_view_render.dart': Failed assertion: line 844 pos 12: 'child.parent == this': is not true.

The relevant error-causing widget was: 
  FlutterSliverList file:///Users/xx/Documents/workspace/xx/flutter_list_view/lib/src/flutter_list_view.dart:161:7
When the exception was thrown, this was the stack: 
#2      FlutterListViewRender.childScrollOffset (package:flutter_list_view/src/flutter_list_view_render.dart:844:12)
#3      FlutterListViewRender.childMainAxisPosition (package:flutter_list_view/src/flutter_list_view_render.dart:838:14)
#4      FlutterListViewRender.paint (package:flutter_list_view/src/flutter_list_view_render.dart:680:36)
#5      RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2317:7)
#6      PaintingContext.paintChild (package:flutter/src/rendering/object.dart:187:13)
...
The following RenderObject was being processed when the exception was fired: FlutterListViewRender#7574b relayoutBoundary=up1
...  needs compositing
...  parentData: paintOffset=Offset(0.0, 0.0) (can use size)
...  constraints: SliverConstraints(AxisDirection.up, GrowthDirection.forward, ScrollDirection.reverse, scrollOffset: 825.5, remainingPaintExtent: 718.0, crossAxisExtent: 432.0, crossAxisDirection: AxisDirection.right, viewportMainAxisExtent: 718.0, remainingCacheExtent: 1218.0, cacheOrigin: -250.0)
...  geometry: SliverGeometry(scrollExtent: 1922.1, paintExtent: 718.0, maxPaintExtent: 718.0, hasVisualOverflow: true, cacheExtent: 1218.0)
...    scrollExtent: 1922.1
...    paintExtent: 718.0
...    maxPaintExtent: 718.0
...    hasVisualOverflow: true
...    cacheExtent: 1218.0
RenderObject: FlutterListViewRender#7574b relayoutBoundary=up1
  needs compositing
  parentData: paintOffset=Offset(0.0, 0.0) (can use size)
  constraints: SliverConstraints(AxisDirection.up, GrowthDirection.forward, ScrollDirection.reverse, scrollOffset: 825.5, remainingPaintExtent: 718.0, crossAxisExtent: 432.0, crossAxisDirection: AxisDirection.right, viewportMainAxisExtent: 718.0, remainingCacheExtent: 1218.0, cacheOrigin: -250.0)
  geometry: SliverGeometry(scrollExtent: 1922.1, paintExtent: 718.0, maxPaintExtent: 718.0, hasVisualOverflow: true, cacheExtent: 1218.0)
    scrollExtent: 1922.1
    paintExtent: 718.0
    maxPaintExtent: 718.0
    hasVisualOverflow: true
    cacheExtent: 1218.0
====================================================================================================