Skip to content

Commit efcf561

Browse files
gnpricechrisbobbe
authored andcommitted
scroll test [nfc]: Share a controller variable in MessageListScrollView tests
This will be convenient for testing scrollToEnd.
1 parent a0f3a29 commit efcf561

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

test/widgets/scrolling_test.dart

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import '../flutter_checks.dart';
88
void main() {
99
group('MessageListScrollView', () {
1010
Widget buildList({
11-
MessageListScrollController? controller,
11+
required MessageListScrollController controller,
1212
required double topHeight,
1313
required double bottomHeight,
1414
}) {
1515
return MessageListScrollView(
16-
controller: controller ?? MessageListScrollController(),
16+
controller: controller,
1717
center: const ValueKey('center'),
1818
slivers: [
1919
SliverToBoxAdapter(
@@ -23,11 +23,16 @@ void main() {
2323
]);
2424
}
2525

26+
late MessageListScrollController controller;
27+
2628
Future<void> prepare(WidgetTester tester, {
27-
MessageListScrollController? controller,
29+
bool reuseController = false,
2830
required double topHeight,
2931
required double bottomHeight,
3032
}) async {
33+
if (!reuseController) {
34+
controller = MessageListScrollController();
35+
}
3136
await tester.pumpWidget(Directionality(textDirection: TextDirection.ltr,
3237
child: buildList(controller: controller,
3338
topHeight: topHeight, bottomHeight: bottomHeight)));
@@ -123,20 +128,18 @@ void main() {
123128
});
124129

125130
testWidgets('stick to end of list when it grows', (tester) async {
126-
final controller = MessageListScrollController();
127-
await prepare(tester, controller: controller,
131+
await prepare(tester,
128132
topHeight: 400, bottomHeight: 400);
129133
check(tester.getRect(findBottom))..top.equals(200)..bottom.equals(600);
130134

131135
// Bottom sliver grows; remain scrolled to (new) bottom.
132-
await prepare(tester, controller: controller,
136+
await prepare(tester, reuseController: true,
133137
topHeight: 400, bottomHeight: 500);
134138
check(tester.getRect(findBottom))..top.equals(100)..bottom.equals(600);
135139
});
136140

137141
testWidgets('when not at end, let it grow without following', (tester) async {
138-
final controller = MessageListScrollController();
139-
await prepare(tester, controller: controller,
142+
await prepare(tester,
140143
topHeight: 400, bottomHeight: 400);
141144
check(tester.getRect(findBottom))..top.equals(200)..bottom.equals(600);
142145

@@ -146,7 +149,7 @@ void main() {
146149
check(tester.getRect(findBottom))..top.equals(300)..bottom.equals(700);
147150

148151
// Bottom sliver grows; remain at existing position, now farther from end.
149-
await prepare(tester, controller: controller,
152+
await prepare(tester, reuseController: true,
150153
topHeight: 400, bottomHeight: 500);
151154
check(tester.getRect(findBottom))..top.equals(300)..bottom.equals(800);
152155
});

0 commit comments

Comments
 (0)