Skip to content

Commit 32c20fb

Browse files
committed
🔧 Update Pack 2 #3
1 parent 15db333 commit 32c20fb

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

lib/src/scroll_transition.dart

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 {

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ dependencies:
1919
flutter:
2020
sdk: flutter
2121
equatable: ^2.0.5
22-
unicode_emojis: ^0.3.0
22+
unicode_emojis: ^0.4.0
2323

2424
dev_dependencies:
2525
flutter_test:

0 commit comments

Comments
 (0)