Skip to content

Commit

Permalink
Fix FlexibleSpaceBar does compositing with near zero opacity.
Browse files Browse the repository at this point in the history
  • Loading branch information
TahaTesser committed Oct 10, 2023
1 parent 7deb535 commit 4422884
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/material/flexible_space_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ class _RenderFlexibleSpaceHeaderOpacity extends RenderOpacity {
if (child == null) {
return;
}
if (opacity == 0) {
if (opacity == 0 || !needsCompositing) {
layer = null;
return;
}
Expand Down
40 changes: 40 additions & 0 deletions packages/flutter/test/material/flexible_space_bar_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,46 @@ void main() {
await tester.pumpAndSettle();
expect(tester.getTopLeft(find.byType(Text)).dx, 72.0);
});

// This is a regression test for https://github.com/flutter/flutter/issues/135698.
testWidgetsWithLeakTracking('_FlexibleSpaceHeaderOpacity with near zero opacity avoids compositing', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
home: Material(
child: NestedScrollView(
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
SliverOverlapAbsorber(
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
sliver: const SliverAppBar(
pinned: true,
expandedHeight: 200.0,
collapsedHeight: 56.0,
flexibleSpace: FlexibleSpaceBar(background: SizedBox()),
),
),
];
},
body: const SingleChildScrollView(
child: Column(
children: <Widget>[
Placeholder(fallbackHeight: 300.0),
],
),
),
),
),
),
);

// Drag the scroll view to the top to collapse the sliver app bar.
// Ensure collapsed height - current extent is near zero for the
// FlexibleSpaceBar to avoid compositing.
await tester.drag(find.byType(SingleChildScrollView), const Offset(0, -(200.0 - 56.08787892026129)));
await tester.pumpAndSettle();

expect(tester.takeException(), isNull);
}, variant: TargetPlatformVariant.mobile());
}

class TestDelegate extends SliverPersistentHeaderDelegate {
Expand Down

0 comments on commit 4422884

Please sign in to comment.