SliverList throws Exception when first item is SizedBox.shrink() #62198
Copy link
Copy link
Closed
Labels
c: crashStack traces logged to the consoleStack traces logged to the consolec: regressionIt was better in the past than it is nowIt was better in the past than it is nowf: scrollingViewports, list views, slivers, etc.Viewports, list views, slivers, etc.found in release: 1.21Found to occur in 1.21Found to occur in 1.21frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onplatform-iosiOS applications specificallyiOS applications specificallyplatform-macosBuilding on or for macOS specificallyBuilding on or for macOS specificallywaiting for PR to land (fixed)A fix is in flightA fix is in flight
Milestone
Description
Steps to Reproduce
Run this snippet:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: CustomScrollView(
physics: AlwaysScrollableScrollPhysics(),
slivers: [
SliverList(
delegate: SliverChildListDelegate(
[const SizedBox.shrink(), Text("item"), Text("item 2")]),
),
],
)),
);
}
}On the current master, dev or beta branch (the previous beta branch, 1.19.0-4.3.pre, works, but 1.20.0-7.2.pre crashes.)
Then fling the screen up a bit, the exception only happens when there is significant overscroll happening.
See https://streamable.com/i7eqce
Expected results:
I want the use case, that the first item of a SliverList is SizedBox.shrink(), be supported.
(Actually, my use case is more complex, I have a Widget that either renders something or returns SizedBox.shrink() if there is nothing to display. I don't want this logic to be in my SliverList, though).
Actual results:
On the latest Flutter versions, this is not supported, and an exception gets thrown:
flutter: ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
flutter: The following assertion was thrown during performLayout():
flutter: 'package:flutter/src/rendering/sliver.dart': Failed assertion: line 556 pos 15:
flutter: 'scrollOffsetCorrection != 0.0': is not true.
flutter:
flutter: Either the assertion indicates an error in the framework itself, or we should provide substantially
flutter: more information in this error message to help you determine and fix the underlying cause.
flutter: In either case, please report this assertion by filing a bug on GitHub:
flutter: https://github.com/flutter/flutter/issues/new?template=BUG.md
flutter:
flutter: The relevant error-causing widget was:
flutter: SliverList file:///Users/kami/development/scroll_bug/lib/main.dart:17:11
flutter:
flutter: When the exception was thrown, this was the stack:
flutter: #2 new SliverGeometry (package:flutter/src/rendering/sliver.dart:556:15)
flutter: #3 RenderSliverList.performLayout (package:flutter/src/rendering/sliver_list.dart:180:20)
flutter: #4 RenderObject.layout (package:flutter/src/rendering/object.dart:1776:7)
flutter: #5 RenderViewportBase.layoutChildSequence (package:flutter/src/rendering/viewport.dart:471:13)
flutter: #6 RenderViewport._attemptLayout (package:flutter/src/rendering/viewport.dart:1466:12)
flutter: #7 RenderViewport.performLayout (package:flutter/src/rendering/viewport.dart:1375:20)
flutter: #8 RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:1639:7)
flutter: #9 PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:896:18)
flutter: #10 RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:404:19)
flutter: #11 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:881:13)
flutter: #12 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:286:5)
flutter: #13 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1114:15)
flutter: #14 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1053:9)
flutter: #15 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:969:5)
flutter: #19 _invoke (dart:ui/hooks.dart:253:10)
flutter: #20 _drawFrame (dart:ui/hooks.dart:211:3)
flutter: (elided 5 frames from class _AssertionError and dart:async)
flutter:
flutter: The following RenderObject was being processed when the exception was fired: RenderSliverList#12304 relayoutBoundary=up1 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE:
flutter: needs compositing
flutter: creator: SliverList ← Viewport ← IgnorePointer-[GlobalKey#77b5f] ← Semantics ← _PointerListener ←
flutter: Listener ← _GestureSemantics ←
flutter: RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#6713c] ← _PointerListener ← Listener
flutter: ← _ScrollableScope ← _ScrollSemantics-[GlobalKey#fde3c] ← ⋯
flutter: parentData: paintOffset=Offset(0.0, 0.0) (can use size)
flutter: constraints: SliverConstraints(AxisDirection.down, GrowthDirection.forward, ScrollDirection.reverse,
flutter: scrollOffset: 240.4, remainingPaintExtent: 667.0, crossAxisExtent: 375.0, crossAxisDirection:
flutter: AxisDirection.right, viewportMainAxisExtent: 667.0, remainingCacheExtent: 1157.4, cacheOrigin:
flutter: -240.4)
flutter: geometry: SliverGeometry(scrollExtent: 17.0, hidden, maxPaintExtent: 17.0)
flutter: currently live children: 0 to 1
flutter: This RenderObject had the following descendants (showing up to depth 5):
flutter: child with index 0: RenderIndexedSemantics#78dd3 relayoutBoundary=up2 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
flutter: child: RenderRepaintBoundary#358a5 relayoutBoundary=up3 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
flutter: child: RenderConstrainedBox#6cefd relayoutBoundary=up4 NEEDS-PAINT
flutter: child with index 1: RenderIndexedSemantics#870ee relayoutBoundary=up2
flutter: child: RenderRepaintBoundary#1f7bf relayoutBoundary=up3
flutter: child: RenderParagraph#951c2 relayoutBoundary=up4
flutter: text: TextSpan
flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════
flutter: Another exception was thrown: 'package:flutter/src/rendering/sliver.dart': Failed assertion: line 556 pos 15: 'scrollOffsetCorrection != 0.0': is not true.
flutter: Another exception was thrown: 'package:flutter/src/rendering/sliver.dart': Failed assertion: line 556 pos 15: 'scrollOffsetCorrection != 0.0': is not true.
flutter: Another exception was thrown: 'package:flutter/src/rendering/sliver.dart': Failed assertion: line 556 pos 15: 'scrollOffsetCorrection != 0.0': is not true.
flutter analyze
Analyzing scroll_bug...
No issues found! (ran in 2.9s)
flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, 1.21.0-6.0.pre.17, on Mac OS X 10.15.5 19F101, locale en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 11.6)
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.0)
[!] IntelliJ IDEA Ultimate Edition (version 2019.1.2)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] VS Code (version 1.47.1)
[✓] Connected device (4 available)
! Doctor found issues in 1 category.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
c: crashStack traces logged to the consoleStack traces logged to the consolec: regressionIt was better in the past than it is nowIt was better in the past than it is nowf: scrollingViewports, list views, slivers, etc.Viewports, list views, slivers, etc.found in release: 1.21Found to occur in 1.21Found to occur in 1.21frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onplatform-iosiOS applications specificallyiOS applications specificallyplatform-macosBuilding on or for macOS specificallyBuilding on or for macOS specificallywaiting for PR to land (fixed)A fix is in flightA fix is in flight
Activity
TahaTesser commentedon Jul 24, 2020
hI @knaeckeKami
i cannot reproduce this on latest
master, if the issue is only reproducible on 1.20.0-7.2.pre crashes. then it might be fixed in latestmasterCode Sample
logs
flutter doctor -v
knaeckeKami commentedon Jul 24, 2020
Hi @TahaTesser !
I checked again and it seems to only happen on IOS devices (simulator or real device) and Desktop.
Android works fine.
I thought it should happen on all devices since I set the scroll physics explicitly, but it seems I was mistaken.
Apologies, next time I will test on more platforms.
However, I can reproduce it on the latest master. Here is a short clip of it happening:
https://streamable.com/i7eqce
You need to fling the screen up a bit, it does only happen if you overscroll quite a bit.
TahaTesser commentedon Jul 27, 2020
@knaeckeKami
Thanks, i can reproduce it on simulator
Code Sample
logs
flutter doctor -v
7 remaining items
Piinks commentedon Jul 29, 2020
I haven't been able to reproduce the crash on the latest master. I think a few changes were introduced/reverted/relanded that may have resolved this like @TahaTesser mentioned before. Can you check again on master?
@venkatd can you provide a runnable reproduction of your experience with this?
I ran this on an iOS simulator and an Android simulator, scrolled around a bit to see if the layout correction would crash, but it looks like it doesn't enter that block of code where it crashed.
I can definitely catch the case where scrollOffsetCorrection may be zero to prevent it from ever happening, I just need to come up with a test case that reproduces the crash.
flutter doctor
knaeckeKami commentedon Jul 29, 2020
Hm, I still am able to reproduce it on the latest master, on iOS and on Mac OS Desktop.
flutter doctor
flutter run
Note that you need to fling up the screen a bit (as seen on this clip here: https://streamable.com/i7eqce ).
Piinks commentedon Jul 29, 2020
Ah! Thank you!
venkatd commentedon Aug 4, 2020
@Piinks sorry I missed this! If you still need a reproduction or verification that the bug was fixed, happy to put one together next week.
knaeckeKami commentedon Aug 5, 2020
Once this gets merged, I would appreciate a hotfix, since this would affect me if I upgraded to the current stable version.
pcsosinski commentedon Aug 7, 2020
under review for CP to 1.20
github-actions commentedon Aug 17, 2021
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.