Unverified Commit b4e9d0a4 authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Add tests for getOffsetToReveal on RenderSlivers (#26598)

parent f22043e2
......@@ -192,6 +192,170 @@ void main() {
expect(revealed.rect, Rect.fromLTWH(0.0, 40.0, 10.0, 10.0));
});
testWidgets('Viewport getOffsetToReveal Sliver - down', (WidgetTester tester) async {
final List<Widget> children = <Widget>[];
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: Container(
height: 200.0,
width: 300.0,
child: CustomScrollView(
controller: ScrollController(initialScrollOffset: 300.0),
slivers: List<Widget>.generate(20, (int i) {
final Widget sliver = SliverToBoxAdapter(
child: Container(
height: 100.0,
child: Text('Tile $i'),
)
);
children.add(sliver);
return SliverPadding(
padding: const EdgeInsets.all(22.0),
sliver: sliver,
);
}),
),
),
),
),
);
final RenderAbstractViewport viewport = tester.allRenderObjects.firstWhere((RenderObject r) => r is RenderAbstractViewport);
final RenderObject target = tester.renderObject(find.byWidget(children[5], skipOffstage: false));
RevealedOffset revealed = viewport.getOffsetToReveal(target, 0.0);
expect(revealed.offset, 5 * (100 + 22 + 22) + 22);
revealed = viewport.getOffsetToReveal(target, 1.0);
expect(revealed.offset, 5 * (100 + 22 + 22) + 22 - 100);
});
testWidgets('Viewport getOffsetToReveal Sliver - right', (WidgetTester tester) async {
final List<Widget> children = <Widget>[];
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: Container(
height: 300.0,
width: 200.0,
child: CustomScrollView(
scrollDirection: Axis.horizontal,
controller: ScrollController(initialScrollOffset: 300.0),
slivers: List<Widget>.generate(20, (int i) {
final Widget sliver = SliverToBoxAdapter(
child: Container(
width: 100.0,
child: Text('Tile $i'),
)
);
children.add(sliver);
return SliverPadding(
padding: const EdgeInsets.all(22.0),
sliver: sliver,
);
}),
),
),
),
),
);
final RenderAbstractViewport viewport = tester.allRenderObjects.firstWhere((RenderObject r) => r is RenderAbstractViewport);
final RenderObject target = tester.renderObject(find.byWidget(children[5], skipOffstage: false));
RevealedOffset revealed = viewport.getOffsetToReveal(target, 0.0);
expect(revealed.offset, 5 * (100 + 22 + 22) + 22);
revealed = viewport.getOffsetToReveal(target, 1.0);
expect(revealed.offset, 5 * (100 + 22 + 22) + 22 - 100);
});
testWidgets('Viewport getOffsetToReveal Sliver - up', (WidgetTester tester) async {
final List<Widget> children = <Widget>[];
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: Container(
height: 200.0,
width: 300.0,
child: CustomScrollView(
controller: ScrollController(initialScrollOffset: 300.0),
reverse: true,
slivers: List<Widget>.generate(20, (int i) {
final Widget sliver = SliverToBoxAdapter(
child: Container(
height: 100.0,
child: Text('Tile $i'),
)
);
children.add(sliver);
return SliverPadding(
padding: const EdgeInsets.all(22.0),
sliver: sliver,
);
}),
),
),
),
),
);
final RenderAbstractViewport viewport = tester.allRenderObjects.firstWhere((RenderObject r) => r is RenderAbstractViewport);
final RenderObject target = tester.renderObject(find.byWidget(children[5], skipOffstage: false));
RevealedOffset revealed = viewport.getOffsetToReveal(target, 0.0);
expect(revealed.offset, 5 * (100 + 22 + 22) + 22);
revealed = viewport.getOffsetToReveal(target, 1.0);
expect(revealed.offset, 5 * (100 + 22 + 22) + 22 - 100);
});
testWidgets('Viewport getOffsetToReveal Sliver - left', (WidgetTester tester) async {
final List<Widget> children = <Widget>[];
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: Container(
height: 300.0,
width: 200.0,
child: CustomScrollView(
scrollDirection: Axis.horizontal,
reverse: true,
controller: ScrollController(initialScrollOffset: 300.0),
slivers: List<Widget>.generate(20, (int i) {
final Widget sliver = SliverToBoxAdapter(
child: Container(
width: 100.0,
child: Text('Tile $i'),
)
);
children.add(sliver);
return SliverPadding(
padding: const EdgeInsets.all(22.0),
sliver: sliver,
);
}),
),
),
),
),
);
final RenderAbstractViewport viewport = tester.allRenderObjects.firstWhere((RenderObject r) => r is RenderAbstractViewport);
final RenderObject target = tester.renderObject(find.byWidget(children[5], skipOffstage: false));
RevealedOffset revealed = viewport.getOffsetToReveal(target, 0.0);
expect(revealed.offset, 5 * (100 + 22 + 22) + 22);
revealed = viewport.getOffsetToReveal(target, 1.0);
expect(revealed.offset, 5 * (100 + 22 + 22) + 22 - 100);
});
testWidgets('Nested Viewports showOnScreen', (WidgetTester tester) async {
final List<List<Widget>> children = List<List<Widget>>(10);
final List<ScrollController> controllersX = List<ScrollController>.generate(10, (int i) => ScrollController(initialScrollOffset: 400.0));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment