Repository navigation
flexible_space_bar.dart': Failed assertion: line 475 pos 12: 'needsCompositing': is not true. is thrown when scrolling down in the list and then up #135698
Copy link
Copy link
Closed
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: error messageError messages from the Flutter frameworkError messages from the Flutter frameworkf: scrollingViewports, list views, slivers, etc.Viewports, list views, slivers, etc.found in release: 3.13Found to occur in 3.13Found to occur in 3.13found in release: 3.16Found to occur in 3.16Found to occur in 3.16frameworkflutter/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 onp: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packagesr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-designOwned by Design Languages teamOwned by Design Languages teamtriaged-designTriaged by Design Languages teamTriaged by Design Languages team
Description
this issue is also represented at #135486
Code sample
main() => runApp(MaterialApp(
home: NestedScrollView(
headerSliverBuilder: (context, _) => [SliverOverlapAbsorber(
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
sliver: SliverAppBar(
expandedHeight: 300,
pinned: true,
flexibleSpace: FlexibleSpaceBar(background: SizedBox()),
),
)],
body: SizedBox(),
),
));Why it happens
the cause for the issue is that RenderOpacity use _alpha to override alwaysNeedsCompositing
and _RenderFlexibleSpaceHeaderOpacity doesn't use it before the needCompositing assertion.
RenderOpacity
RenderOpacity({
double opacity = 1.0,
bool alwaysIncludeSemantics = false,
RenderBox? child,
}) : assert(opacity >= 0.0 && opacity <= 1.0),
_opacity = opacity,
_alwaysIncludeSemantics = alwaysIncludeSemantics,
_alpha = ui.Color.getAlphaFromOpacity(opacity),
super(child);
@override
bool get alwaysNeedsCompositing => child != null && _alpha > 0;My Recommended solution
_RenderFlexibleSpaceHeaderOpacity:
before
if (opacity == 0) {
layer = null;
return;
}
assert(needsCompositing);after
if (ui.Color.getAlphaFromOpacity(opacity) == 0) {
layer = null;
return;
}
assert(needsCompositing);Logs
Logs
======== Exception caught by rendering library =====================================================
The following assertion was thrown during paint():
'package:flutter/src/material/flexible_space_bar.dart': Failed assertion: line 467 pos 12: 'needsCompositing': is not true.
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.yml
The relevant error-causing widget was:
FlexibleSpaceBar FlexibleSpaceBar:file:///C:/Users/shlom/StudioProjects/imagine-ai/lib/pages/settings_page/cloud_page/cloud_app_bar.dart:27:24
When the exception was thrown, this was the stack:
#2 _RenderFlexibleSpaceHeaderOpacity.paint (package:flutter/src/material/flexible_space_bar.dart:467:12)
#3 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3155:7)
#4 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:252:13)
#5 RenderBoxContainerDefaultsMixin.defaultPaint (package:flutter/src/rendering/box.dart:2875:15)
#6 RenderStack.paintStack (package:flutter/src/rendering/stack.dart:639:5)
#7 PaintingContext.pushClipRect.<anonymous closure> (package:flutter/src/rendering/object.dart:535:83)
#8 ClipContext._clipAndPaint (package:flutter/src/painting/clip.dart:25:12)
#9 ClipContext.clipRectAndPaint (package:flutter/src/painting/clip.dart:53:5)
#10 PaintingContext.pushClipRect (package:flutter/src/rendering/object.dart:535:7)
#11 RenderStack.paint (package:flutter/src/rendering/stack.dart:645:38)
#12 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3155:7)
#13 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:252:13)
#14 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:129:13)
#15 PaintingContext.pushClipRect.<anonymous closure> (package:flutter/src/rendering/object.dart:535:83)
#16 ClipContext._clipAndPaint (package:flutter/src/painting/clip.dart:25:12)
#17 ClipContext.clipRectAndPaint (package:flutter/src/painting/clip.dart:53:5)
#18 PaintingContext.pushClipRect (package:flutter/src/rendering/object.dart:535:7)
#19 RenderClipRect.paint (package:flutter/src/rendering/proxy_box.dart:1530:25)
#20 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3155:7)
#21 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:252:13)
#22 _RenderLayoutBuilder.paint (package:flutter/src/widgets/layout_builder.dart:338:15)
#23 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3155:7)
#24 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:252:13)
#25 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:129:13)
#26 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3155:7)
#27 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:252:13)
#28 RenderBoxContainerDefaultsMixin.defaultPaint (package:flutter/src/rendering/box.dart:2875:15)
#29 RenderStack.paintStack (package:flutter/src/rendering/stack.dart:639:5)
#30 RenderStack.paint (package:flutter/src/rendering/stack.dart:655:7)
#31 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3155:7)
#32 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:252:13)
#33 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:129:13)
#34 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3155:7)
#35 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:252:13)
#36 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:129:13)
#37 _RenderInkFeatures.paint (package:flutter/src/material/material.dart:664:11)
#38 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3155:7)
#39 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:252:13)
#40 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:129:13)
#41 RenderPhysicalModel.paint.<anonymous closure> (package:flutter/src/rendering/proxy_box.dart:2049:15)
#42 PaintingContext.pushClipRRect (package:flutter/src/rendering/object.dart:561:14)
#43 RenderPhysicalModel.paint (package:flutter/src/rendering/proxy_box.dart:2036:21)
#44 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3155:7)
#45 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:252:13)
#46 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:129:13)
#47 PaintingContext.pushLayer (package:flutter/src/rendering/object.dart:472:12)
#48 RenderAnnotatedRegion.paint (package:flutter/src/rendering/proxy_box.dart:5045:13)
#49 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3155:7)
#50 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:252:13)
#51 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:129:13)
#52 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3155:7)
#53 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:252:13)
#54 RenderSliverPersistentHeader.paint (package:flutter/src/rendering/sliver_persistent_header.dart:311:15)
#55 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3155:7)
#56 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:252:13)
#57 RenderSliverOverlapAbsorber.paint (package:flutter/src/widgets/nested_scroll_view.dart:1827:15)
#58 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3155:7)
#59 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:252:13)
#60 RenderViewportBase._paintContents (package:flutter/src/rendering/viewport.dart:690:17)
#61 PaintingContext.pushLayer (package:flutter/src/rendering/object.dart:472:12)
#62 PaintingContext.pushClipRect (package:flutter/src/rendering/object.dart:532:7)
#63 RenderViewportBase.paint (package:flutter/src/rendering/viewport.dart:665:38)
#64 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3155:7)
#65 PaintingContext._repaintCompositedChild (package:flutter/src/rendering/object.dart:168:11)
#66 PaintingContext.repaintCompositedChild (package:flutter/src/rendering/object.dart:111:5)
#67 PipelineOwner.flushPaint (package:flutter/src/rendering/object.dart:1144:31)
#68 RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:496:19)
#69 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:918:13)
#70 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:360:5)
#71 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1297:15)
#72 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1227:9)
#73 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1085:5)
#74 _invoke (dart:ui/hooks.dart:170:13)
#75 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:401:5)
#76 _drawFrame (dart:ui/hooks.dart:140:31)
(elided 2 frames from class _AssertionError)
The following RenderObject was being processed when the exception was fired: _RenderFlexibleSpaceHeaderOpacity#07433
... parentData: top=-39.5; right=0.0; left=0.0; height=295.5; offset=Offset(0.0, -39.5) (can use size)
... constraints: BoxConstraints(w=345.6, h=295.5)
... layer: OpacityLayer#dd7ac DETACHED
... engine layer: OpacityEngineLayer#091af
... handles: 2
... offset: Offset(0.0, -30.9)
... alpha: 156
... size: Size(345.6, 295.5)
... opacity: 0.0
... alwaysIncludeSemantics
RenderObject: _RenderFlexibleSpaceHeaderOpacity#07433
parentData: top=-39.5; right=0.0; left=0.0; height=295.5; offset=Offset(0.0, -39.5) (can use size)
constraints: BoxConstraints(w=345.6, h=295.5)
layer: OpacityLayer#dd7ac DETACHED
engine layer: OpacityEngineLayer#091af
handles: 2
offset: Offset(0.0, -30.9)
alpha: 156
size: Size(345.6, 295.5)
opacity: 0.0
alwaysIncludeSemanticsFlutter Doctor output
Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel beta, 3.13.0-0.3.pre, on Microsoft Windows [Version 10.0.22621.2283], locale en-IL)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.5.5)
[√] Android Studio (version 4.1)
[√] Android Studio (version 2021.2)
[√] Android Studio (version 2023.1)
[√] VS Code (version 1.82.2)
[√] Connected device (4 available)
[√] Network resources
• No issues found!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: error messageError messages from the Flutter frameworkError messages from the Flutter frameworkf: scrollingViewports, list views, slivers, etc.Viewports, list views, slivers, etc.found in release: 3.13Found to occur in 3.13Found to occur in 3.13found in release: 3.16Found to occur in 3.16Found to occur in 3.16frameworkflutter/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 onp: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packagesr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-designOwned by Design Languages teamOwned by Design Languages teamtriaged-designTriaged by Design Languages teamTriaged by Design Languages team
Type
Projects
- StatusShow more project fieldsDone (PR merged)
Activity
[-]'package:flutter/src/material/flexible_space_bar.dart': Failed assertion: line 467 pos 12: 'needsCompositing': is not true.[/-][+]Failed assertion: line 467 pos 12: 'needsCompositing': is not true.[/+]huycozy commentedon Sep 29, 2023
Hi @CardosoShlomo
Could you share the steps to reproduce this issue? I can't reproduce it on the latest Flutter channels with your sample code above. Verifying on Android platform.
flutter doctor -v (stable, beta, master)
[✓] Flutter (Channel stable, 3.13.6, on macOS 14.0 23A344 darwin-x64, locale en-VN) • Flutter version 3.13.6 on channel stable at /Users/huynq/Documents/GitHub/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision ead455963c (2 days ago), 2023-09-26 18:28:17 -0700 • Engine revision a794cf2681 • Dart version 3.1.3 • DevTools version 2.25.0 [✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0) • Android SDK at /Users/huynq/Library/Android/sdk • Platform android-34, build-tools 32.0.0 • ANDROID_HOME = /Users/huynq/Library/Android/sdk • Java binary at: /Applications/Android Studio Giraffe.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 15.0) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 15A240d • CocoaPods version 1.11.3 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2022.3) • Android Studio at /Applications/Android Studio Giraffe.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231) [✓] Android Studio (version 2022.2) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694) [✓] VS Code (version 1.82.2) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.72.0 [✓] Connected device (2 available) • macOS (desktop) • macos • darwin-x64 • macOS 14.0 23A344 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 117.0.5938.132 [✓] Network resources • All expected network resources are available. • No issues found!ThHareau commentedon Oct 4, 2023
Hey, I can repro as well, but with an example a bit more complex:
Disclaimer: I'm relatively new to flutter, maybe I do not understand something here
Then to repro, on android, scroll down in the list and then up. When scrolling up in the list the exception should occur.
I tried on dart pad or linux sdk, I wasn't able to repro.
My flutter doctor:
huycozy commentedon Oct 5, 2023
Thank @ThHareau for the sample code and steps to reproduce, I also can reproduce it on the latest master channel.
Output exception
flutter doctor -v (stable and master)
[✓] Flutter (Channel stable, 3.13.6, on macOS 14.0 23A344 darwin-x64, locale en-VN) • Flutter version 3.13.6 on channel stable at /Users/huynq/Documents/GitHub/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision ead455963c (5 days ago), 2023-09-26 18:28:17 -0700 • Engine revision a794cf2681 • Dart version 3.1.3 • DevTools version 2.25.0 [✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0) • Android SDK at /Users/huynq/Library/Android/sdk • Platform android-34, build-tools 32.0.0 • ANDROID_HOME = /Users/huynq/Library/Android/sdk • Java binary at: /Applications/Android Studio Giraffe.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 15.0) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 15A240d • CocoaPods version 1.11.3 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2022.3) • Android Studio at /Applications/Android Studio Giraffe.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231) [✓] Android Studio (version 2022.2) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694) [✓] VS Code (version 1.82.2) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.72.0 [✓] Connected device (2 available) • macOS (desktop) • macos • darwin-x64 • macOS 14.0 23A344 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 117.0.5938.132 [✓] Network resources • All expected network resources are available. • No issues found!1 remaining item
[-]Failed assertion: line 467 pos 12: 'needsCompositing': is not true.[/-][+]`flexible_space_bar.dart': Failed assertion: line 475 pos 12: 'needsCompositing': is not true.` is thrown when scrolling down in the list and then up [/+]Succi-c commentedon Oct 10, 2023
I have also encountered a similar problem. Does this error have a significant impact? Which official version can solve it?
Fix `FlexibleSpaceBar` does compositing with near zero opacity. (#136255
github-actions commentedon Oct 25, 2023
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.