flutter_staggered_grid_view
flutter_staggered_grid_view copied to clipboard
Null error when scrolling back to the top
══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
The following _TypeError was thrown during performLayout():
Null check operator used on a null value
The relevant error-causing widget was:
SliverMasonryGrid
SliverMasonryGrid:file:///X:/AndroidStudioProjects/apnapan/lib/feed/components/posts_list.dart:102:31
When the exception was thrown, this was the stack:
#0 RenderSliverMasonryGrid.performLayout
(package:flutter_staggered_grid_view/src/rendering/sliver_masonry_grid.dart:489:51)
#1 RenderObject.layout (package:flutter/src/rendering/object.dart:2577:7)
#2 RenderViewportBase.layoutChildSequence (package:flutter/src/rendering/viewport.dart:601:13)
#3 RenderViewport._attemptLayout (package:flutter/src/rendering/viewport.dart:1516:12)
#4 RenderViewport.performLayout (package:flutter/src/rendering/viewport.dart:1427:20)
#5 RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:2416:7)
#6 PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:1051:18)
#7 PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:1064:15)
#8 RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:577:23)
#9 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:1138:13)
#10 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:443:5)
#11 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1392:15)
#12 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1313:9)
#13 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1171:5)
#14 _invoke (dart:ui/hooks.dart:312:13)
#15 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:419:5)
#16 _drawFrame (dart:ui/hooks.dart:283:31)
The following RenderObject was being processed when the exception was fired: RenderSliverMasonryGrid#bffdf
relayoutBoundary=up1 NEEDS-LAYOUT NEEDS-COMPOSITING-BITS-UPDATE:
needs compositing
creator: SliverMasonryGrid ← Viewport ← IgnorePointer-[GlobalKey#50b7e] ← Semantics ← Listener ←
_GestureSemantics ← RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#fd6c9] ←
Listener ← _ScrollableScope ← _ScrollSemantics-[GlobalKey#6a384] ←
NotificationListener<ScrollMetricsNotification> ← Transform ← ⋯
parentData: paintOffset=Offset(0.0, 0.0) (can use size)
constraints: SliverConstraints(AxisDirection.down, GrowthDirection.forward, ScrollDirection.idle,
scrollOffset: 225.7, precedingScrollExtent: 4.0, remainingPaintExtent: 914.3, crossAxisExtent:
403.4, crossAxisDirection: AxisDirection.right, viewportMainAxisExtent: 914.3,
remainingCacheExtent: 1390.0, cacheOrigin: -225.7)
geometry: SliverGeometry(scrollExtent: 3316.6, paintExtent: 914.3, maxPaintExtent: 3316.6,
hasVisualOverflow: true, cacheExtent: 1414.3)
currently live children: 0 to 11
This RenderObject had the following descendants (showing up to depth 5):
child with index 0: RenderIndexedSemantics#35b58 relayoutBoundary=up2 NEEDS-PAINT
NEEDS-COMPOSITING-BITS-UPDATE
child: RenderRepaintBoundary#9c93e relayoutBoundary=up3 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
child: RenderConstrainedBox#78b24 relayoutBoundary=up4 NEEDS-PAINT
child with index 1: RenderIndexedSemantics#898b5 relayoutBoundary=up2 NEEDS-PAINT
NEEDS-COMPOSITING-BITS-UPDATE
child: RenderRepaintBoundary#49a75 relayoutBoundary=up3 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
child: RenderConstrainedBox#c2cdc relayoutBoundary=up4 NEEDS-PAINT
child with index 2: RenderIndexedSemantics#f301f relayoutBoundary=up2 NEEDS-PAINT
NEEDS-COMPOSITING-BITS-UPDATE
child: RenderRepaintBoundary#c7319 relayoutBoundary=up3 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
child: RenderConstrainedBox#da06f relayoutBoundary=up4 NEEDS-PAINT
child with index 3: RenderIndexedSemantics#4535c relayoutBoundary=up2 NEEDS-PAINT
NEEDS-COMPOSITING-BITS-UPDATE
child: RenderRepaintBoundary#d4123 relayoutBoundary=up3 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
child: RenderConstrainedBox#e2327 relayoutBoundary=up4 NEEDS-PAINT
child with index 4: RenderIndexedSemantics#4b89e relayoutBoundary=up2
child: RenderRepaintBoundary#de96e relayoutBoundary=up3
child: RenderFlex#4aba9 relayoutBoundary=up4
child 1: RenderSemanticsAnnotations#80468 relayoutBoundary=up5
child: RenderPadding#4ebe6 relayoutBoundary=up6
child with index 5: RenderIndexedSemantics#a9a31 relayoutBoundary=up2
child: RenderRepaintBoundary#05f4e relayoutBoundary=up3
child: RenderConstrainedBox#dc7eb relayoutBoundary=up4
child with index 6: RenderIndexedSemantics#05a86 relayoutBoundary=up2
child: RenderRepaintBoundary#29eaa relayoutBoundary=up3
child: RenderConstrainedBox#bf917 relayoutBoundary=up4
child with index 7: RenderIndexedSemantics#a8280 relayoutBoundary=up2
child: RenderRepaintBoundary#c744d relayoutBoundary=up3
child: RenderConstrainedBox#2d657 relayoutBoundary=up4
════════════════════════════════════════════════════════════════════════════════════════════════════
I encountered the same problem. I was able to work around it by using this approach:
SingleChildScrollView(
child: MasonryGridView(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
...
)
)
This causes the whole grid view to be rendered instantly, and it doesn't have the problem when scrolling up. Of course, losing the advantage of offloading offscreen widgets.
Another similar approach would be to increase the cacheExtend so that the upper children stay cached.