Skip to content

Commit 4673e20

Browse files
authored
Fix TreeSliver rendering offset. (flutter#166442)
Fixes: flutter#166326 The issue lies only in the `paint` method, and there are no problems with `tester.getTopLeft`. Therefore, I used a golden file test. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent fda7ffb commit 4673e20

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

packages/flutter/lib/src/rendering/sliver_tree.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,8 @@ class RenderTreeSliver extends RenderSliverVariedExtentList {
332332
while (child != null && indexOf(child) <= index) {
333333
final double mainAxisDelta = childMainAxisPosition(child);
334334
final TreeSliverNodeParentData parentData = child.parentData! as TreeSliverNodeParentData;
335-
final Offset childOffset = Offset(parentData.depth * indentation, parentData.layoutOffset!);
335+
final Offset childOffset =
336+
Offset(parentData.depth * indentation, parentData.layoutOffset!) + offset;
336337

337338
// If the child's visible interval (mainAxisDelta, mainAxisDelta + paintExtentOf(child))
338339
// does not intersect the paint extent interval (0, constraints.remainingPaintExtent), it's hidden.

packages/flutter/test/widgets/sliver_tree_test.dart

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
// This file is run as part of a reduced test set in CI on Mac and Windows
6+
// machines.
7+
@Tags(<String>['reduced-test-set'])
8+
library;
9+
510
import 'package:flutter/material.dart';
611
import 'package:flutter/rendering.dart';
712
import 'package:flutter_test/flutter_test.dart';
@@ -861,4 +866,43 @@ void main() {
861866
});
862867
},
863868
);
869+
870+
testWidgets('TreeSliver and PinnedHeaderSliver can render correctly when used together.', (
871+
WidgetTester tester,
872+
) async {
873+
const ValueKey<String> key = ValueKey<String>('sliver_tree_pined_header');
874+
await tester.pumpWidget(
875+
Directionality(
876+
textDirection: TextDirection.ltr,
877+
child: Align(
878+
alignment: Alignment.topLeft,
879+
child: RepaintBoundary(
880+
key: key,
881+
child: SizedBox(
882+
height: 20,
883+
width: 20,
884+
child: CustomScrollView(
885+
slivers: <Widget>[
886+
const PinnedHeaderSliver(child: SizedBox(height: 10)),
887+
TreeSliver<Object>(
888+
tree: <TreeSliverNode<Object>>[TreeSliverNode<Object>(Object())],
889+
treeRowExtentBuilder: (_, _) => 10,
890+
treeNodeBuilder: (
891+
BuildContext context,
892+
TreeSliverNode<Object?> node,
893+
AnimationStyle animationStyle,
894+
) {
895+
return const ColoredBox(color: Colors.red);
896+
},
897+
),
898+
],
899+
),
900+
),
901+
),
902+
),
903+
),
904+
);
905+
await expectLater(find.byKey(key), matchesGoldenFile('sliver_tree.pined_header.0.png'));
906+
expect(tester.getTopLeft(find.byType(ColoredBox)), const Offset(0, 10));
907+
});
864908
}

0 commit comments

Comments
 (0)