@@ -11,62 +11,77 @@ import 'test_data.dart';
11
11
12
12
/// Creates an infinite list of Material cards and scrolls it.
13
13
class BenchCardInfiniteScroll extends WidgetRecorder {
14
- BenchCardInfiniteScroll () : super (name: benchmarkName);
14
+ BenchCardInfiniteScroll .forward ()
15
+ : initialOffset = 0.0 ,
16
+ finalOffset = 30000.0 ,
17
+ super (name: benchmarkName);
18
+
19
+ BenchCardInfiniteScroll .backward ()
20
+ : initialOffset = 30000.0 ,
21
+ finalOffset = 0.0 ,
22
+ super (name: benchmarkNameBackward);
15
23
16
24
static const String benchmarkName = 'bench_card_infinite_scroll' ;
25
+ static const String benchmarkNameBackward = 'bench_card_infinite_scroll_backward' ;
26
+
27
+ final double initialOffset;
28
+ final double finalOffset;
17
29
18
30
@override
19
- Widget createWidget () => const MaterialApp (
20
- title: 'Infinite Card Scroll Benchmark' ,
21
- home: _InfiniteScrollCards (),
22
- );
31
+ Widget createWidget () => MaterialApp (
32
+ title: 'Infinite Card Scroll Benchmark' ,
33
+ home: _InfiniteScrollCards (initialOffset, finalOffset ),
34
+ );
23
35
}
24
36
25
37
class _InfiniteScrollCards extends StatefulWidget {
26
- const _InfiniteScrollCards ({Key key}) : super (key: key);
38
+ const _InfiniteScrollCards (this .initialOffset, this .finalOffset, {Key key}) : super (key: key);
39
+
40
+ final double initialOffset;
41
+ final double finalOffset;
27
42
28
43
@override
29
44
State <_InfiniteScrollCards > createState () => _InfiniteScrollCardsState ();
30
45
}
31
46
32
47
class _InfiniteScrollCardsState extends State <_InfiniteScrollCards > {
33
- ScrollController scrollController ;
48
+ static const Duration stepDuration = Duration (seconds : 20 ) ;
34
49
50
+ ScrollController scrollController;
35
51
double offset;
36
- static const double distance = 1000 ;
37
- static const Duration stepDuration = Duration (seconds: 1 );
38
52
39
53
@override
40
54
void initState () {
41
55
super .initState ();
42
56
43
- scrollController = ScrollController ();
44
- offset = 0 ;
57
+ offset = widget.initialOffset;
58
+
59
+ scrollController = ScrollController (
60
+ initialScrollOffset: offset,
61
+ );
45
62
46
63
// Without the timer the animation doesn't begin.
47
64
Timer .run (() async {
48
- while (true ) {
49
- await scrollController.animateTo (
50
- offset + distance,
51
- curve: Curves .linear,
52
- duration: stepDuration,
53
- );
54
- offset += distance;
55
- }
65
+ await scrollController.animateTo (
66
+ widget.finalOffset,
67
+ curve: Curves .linear,
68
+ duration: stepDuration,
69
+ );
56
70
});
57
71
}
58
72
59
73
@override
60
74
Widget build (BuildContext context) {
61
75
return ListView .builder (
62
76
controller: scrollController,
77
+ itemExtent: 100.0 ,
63
78
itemBuilder: (BuildContext context, int index) {
64
79
return SizedBox (
65
80
height: 100.0 ,
66
81
child: Card (
67
82
elevation: 16.0 ,
68
83
child: Text (
69
- lipsum[index % lipsum.length],
84
+ '${ lipsum [index % lipsum .length ]} $ index ' ,
70
85
textAlign: TextAlign .center,
71
86
),
72
87
),
0 commit comments