@@ -8,12 +8,12 @@ import '../flutter_checks.dart';
8
8
void main () {
9
9
group ('MessageListScrollView' , () {
10
10
Widget buildList ({
11
- MessageListScrollController ? controller,
11
+ required MessageListScrollController controller,
12
12
required double topHeight,
13
13
required double bottomHeight,
14
14
}) {
15
15
return MessageListScrollView (
16
- controller: controller ?? MessageListScrollController () ,
16
+ controller: controller,
17
17
center: const ValueKey ('center' ),
18
18
slivers: [
19
19
SliverToBoxAdapter (
@@ -23,11 +23,16 @@ void main() {
23
23
]);
24
24
}
25
25
26
+ late MessageListScrollController controller;
27
+
26
28
Future <void > prepare (WidgetTester tester, {
27
- MessageListScrollController ? controller ,
29
+ bool reuseController = false ,
28
30
required double topHeight,
29
31
required double bottomHeight,
30
32
}) async {
33
+ if (! reuseController) {
34
+ controller = MessageListScrollController ();
35
+ }
31
36
await tester.pumpWidget (Directionality (textDirection: TextDirection .ltr,
32
37
child: buildList (controller: controller,
33
38
topHeight: topHeight, bottomHeight: bottomHeight)));
@@ -123,20 +128,18 @@ void main() {
123
128
});
124
129
125
130
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,
128
132
topHeight: 400 , bottomHeight: 400 );
129
133
check (tester.getRect (findBottom))..top.equals (200 )..bottom.equals (600 );
130
134
131
135
// Bottom sliver grows; remain scrolled to (new) bottom.
132
- await prepare (tester, controller : controller ,
136
+ await prepare (tester, reuseController : true ,
133
137
topHeight: 400 , bottomHeight: 500 );
134
138
check (tester.getRect (findBottom))..top.equals (100 )..bottom.equals (600 );
135
139
});
136
140
137
141
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,
140
143
topHeight: 400 , bottomHeight: 400 );
141
144
check (tester.getRect (findBottom))..top.equals (200 )..bottom.equals (600 );
142
145
@@ -146,7 +149,7 @@ void main() {
146
149
check (tester.getRect (findBottom))..top.equals (300 )..bottom.equals (700 );
147
150
148
151
// Bottom sliver grows; remain at existing position, now farther from end.
149
- await prepare (tester, controller : controller ,
152
+ await prepare (tester, reuseController : true ,
150
153
topHeight: 400 , bottomHeight: 500 );
151
154
check (tester.getRect (findBottom))..top.equals (300 )..bottom.equals (800 );
152
155
});
0 commit comments