@@ -27,11 +27,23 @@ class ScrollTransitionEvent {
2727 /// towards -1. It clamps to -1 when the item is fully out of the scroll view.
2828 final double screenOffsetFraction;
2929
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+
3039 /// Creates a [ScrollTransitionEvent] .
3140 ScrollTransitionEvent ({
3241 required this .phase,
3342 required this .phaseOffsetFraction,
3443 required this .screenOffsetFraction,
44+ required this .scrollPixels,
45+ required this .viewportSize,
46+ required this .scrollDelta,
3547 });
3648}
3749
@@ -93,6 +105,13 @@ class _ScrollTransitionState extends State<ScrollTransition> {
93105 /// animation through the parent viewport.
94106 double screenOffsetFraction = 0 ;
95107
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+
96115 @override
97116 void didChangeDependencies () {
98117 super .didChangeDependencies ();
@@ -197,6 +216,11 @@ class _ScrollTransitionState extends State<ScrollTransition> {
197216 this .phase = phase;
198217 this .phaseOffsetFraction = phaseOffsetFraction;
199218 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;
200224
201225 if (mounted) setState (() {});
202226 }
@@ -220,6 +244,13 @@ class _ScrollTransitionState extends State<ScrollTransition> {
220244 phase: phase,
221245 phaseOffsetFraction: phaseOffsetFraction,
222246 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,
223254 )) ??
224255 widget.child;
225256 } else {
0 commit comments