@@ -129,12 +129,12 @@ void main() {
129
129
130
130
group ('MessageListScrollView' , () {
131
131
Widget buildList ({
132
- MessageListScrollController ? controller,
132
+ required MessageListScrollController controller,
133
133
required double topHeight,
134
134
required double bottomHeight,
135
135
}) {
136
136
return MessageListScrollView (
137
- controller: controller ?? MessageListScrollController () ,
137
+ controller: controller,
138
138
center: const ValueKey ('center' ),
139
139
slivers: [
140
140
SliverToBoxAdapter (
@@ -144,11 +144,16 @@ void main() {
144
144
]);
145
145
}
146
146
147
+ late MessageListScrollController controller;
148
+
147
149
Future <void > prepare (WidgetTester tester, {
148
- MessageListScrollController ? controller ,
150
+ bool reuseController = false ,
149
151
required double topHeight,
150
152
required double bottomHeight,
151
153
}) async {
154
+ if (! reuseController) {
155
+ controller = MessageListScrollController ();
156
+ }
152
157
await tester.pumpWidget (Directionality (textDirection: TextDirection .ltr,
153
158
child: buildList (controller: controller,
154
159
topHeight: topHeight, bottomHeight: bottomHeight)));
@@ -244,20 +249,18 @@ void main() {
244
249
});
245
250
246
251
testWidgets ('stick to end of list when it grows' , (tester) async {
247
- final controller = MessageListScrollController ();
248
- await prepare (tester, controller: controller,
252
+ await prepare (tester,
249
253
topHeight: 400 , bottomHeight: 400 );
250
254
check (tester.getRect (findBottom))..top.equals (200 )..bottom.equals (600 );
251
255
252
256
// Bottom sliver grows; remain scrolled to (new) bottom.
253
- await prepare (tester, controller : controller ,
257
+ await prepare (tester, reuseController : true ,
254
258
topHeight: 400 , bottomHeight: 500 );
255
259
check (tester.getRect (findBottom))..top.equals (100 )..bottom.equals (600 );
256
260
});
257
261
258
262
testWidgets ('when not at end, let it grow without following' , (tester) async {
259
- final controller = MessageListScrollController ();
260
- await prepare (tester, controller: controller,
263
+ await prepare (tester,
261
264
topHeight: 400 , bottomHeight: 400 );
262
265
check (tester.getRect (findBottom))..top.equals (200 )..bottom.equals (600 );
263
266
@@ -267,7 +270,7 @@ void main() {
267
270
check (tester.getRect (findBottom))..top.equals (300 )..bottom.equals (700 );
268
271
269
272
// Bottom sliver grows; remain at existing position, now farther from end.
270
- await prepare (tester, controller : controller ,
273
+ await prepare (tester, reuseController : true ,
271
274
topHeight: 400 , bottomHeight: 500 );
272
275
check (tester.getRect (findBottom))..top.equals (300 )..bottom.equals (800 );
273
276
});
0 commit comments