Skip to content

Commit e583ffa

Browse files
gnpricechrisbobbe
authored andcommitted
scroll [nfc]: Clarify scroll-to-end calculations a bit more
This version keeps the numbers in the form of doubles, with seconds as the unit of time, until the end. That's a bit more typical Flutter style, and also brings it closer to how the logic will look when we flip this around to produce a velocity instead of a duration.
1 parent b3a78d8 commit e583ffa

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

lib/widgets/scrolling.dart

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,11 @@ class MessageListScrollPosition extends ScrollPositionWithSingleContext {
197197
const minDuration = Duration(milliseconds: 300);
198198

199199
final target = maxScrollExtent;
200-
final distance = target - pixels;
201-
final durationMsAtSpeedLimit = (1000 * distance / topSpeed).ceil();
202-
final durationMs = math.max(minDuration.inMilliseconds, durationMsAtSpeedLimit);
203-
animateTo(
204-
target,
205-
duration: Duration(milliseconds: durationMs),
206-
curve: Curves.linear);
200+
final durationSecAtSpeedLimit = (target - pixels) / topSpeed;
201+
final durationSec = math.max(durationSecAtSpeedLimit,
202+
minDuration.inMilliseconds / 1000.0);
203+
final duration = Duration(milliseconds: (durationSec * 1000.0).ceil());
204+
animateTo(target, duration: duration, curve: Curves.linear);
207205
}
208206
}
209207

0 commit comments

Comments
 (0)