@@ -27,11 +27,23 @@ class ScrollTransitionEvent {
27
27
/// towards -1. It clamps to -1 when the item is fully out of the scroll view.
28
28
final double screenOffsetFraction;
29
29
30
+ /// The number of pixels scrolled inside of the parent scroll view.
31
+ final double ? scrollPixels;
32
+
33
+ /// The height or width of the parent scroll view.
34
+ final double ? viewportSize;
35
+
36
+ /// The change in scroll position since the last update.
37
+ final double scrollDelta;
38
+
30
39
/// Creates a [ScrollTransitionEvent] .
31
40
ScrollTransitionEvent ({
32
41
required this .phase,
33
42
required this .phaseOffsetFraction,
34
43
required this .screenOffsetFraction,
44
+ required this .scrollPixels,
45
+ required this .viewportSize,
46
+ required this .scrollDelta,
35
47
});
36
48
}
37
49
@@ -93,6 +105,13 @@ class _ScrollTransitionState extends State<ScrollTransition> {
93
105
/// animation through the parent viewport.
94
106
double screenOffsetFraction = 0 ;
95
107
108
+ /// Keeps track of the last scroll position in pixels.
109
+ /// This is used to calculate the [_scrollDelta] .
110
+ double ? _lastScrollPixels;
111
+
112
+ /// The change in scroll position since the last update.
113
+ double _scrollDelta = 0 ;
114
+
96
115
@override
97
116
void didChangeDependencies () {
98
117
super .didChangeDependencies ();
@@ -197,6 +216,11 @@ class _ScrollTransitionState extends State<ScrollTransition> {
197
216
this .phase = phase;
198
217
this .phaseOffsetFraction = phaseOffsetFraction;
199
218
this .screenOffsetFraction = screenOffsetFraction;
219
+ final double currentPixels =
220
+ scrollPosition? .hasPixels == true ? scrollPosition! .pixels : 0.0 ;
221
+ _scrollDelta =
222
+ _lastScrollPixels != null ? currentPixels - _lastScrollPixels! : 0 ;
223
+ _lastScrollPixels = currentPixels;
200
224
201
225
if (mounted) setState (() {});
202
226
}
@@ -220,6 +244,13 @@ class _ScrollTransitionState extends State<ScrollTransition> {
220
244
phase: phase,
221
245
phaseOffsetFraction: phaseOffsetFraction,
222
246
screenOffsetFraction: screenOffsetFraction,
247
+ scrollPixels: scrollPosition? .hasPixels == true
248
+ ? scrollPosition! .pixels
249
+ : null ,
250
+ viewportSize: scrollPosition? .hasViewportDimension == true
251
+ ? scrollPosition! .viewportDimension
252
+ : null ,
253
+ scrollDelta: _scrollDelta,
223
254
)) ??
224
255
widget.child;
225
256
} else {
0 commit comments