Skip to content

Commit 3db7323

Browse files
committed
msglist: Drop easing curve in scroll-to-bottom
Fundamentally an easing curve like this relies on knowing in advance how far the animation is going to end up going. When we start letting the message list scroll from the middle of history, it'll no longer be possible to know that. Switch instead to a behavior that can be based on only what's happened so far, not on a prediction of the future. In the future, if we want, we could get fancy and make the speed change over time; but to start, keep it simple, and just move at the same speed from start to finish.
1 parent 7309915 commit 3db7323

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

lib/widgets/message_list.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ class ScrollToBottomButton extends StatelessWidget {
704704
return scrollController.animateTo(
705705
target,
706706
duration: Duration(milliseconds: durationMs),
707-
curve: Curves.ease);
707+
curve: Curves.linear);
708708
}
709709

710710
@override

test/widgets/message_list_test.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,8 @@ void main() {
511511
check(isButtonVisible(tester)).equals(false);
512512
});
513513

514-
testWidgets('scrolls at reasonable speed', (tester) async {
515-
const referenceSpeed = 8000.0;
514+
testWidgets('scrolls at reasonable, constant speed', (tester) async {
515+
const maxSpeed = 8000.0;
516516
const distance = 40000.0;
517517
await setupMessageListPage(tester, messageCount: 1000);
518518
final controller = findMessageListScrollController(tester)!;
@@ -536,9 +536,10 @@ void main() {
536536
pos = controller.position.pixels;
537537
log.add(pos - lastPos);
538538
}
539-
// Check the main question: the speed stayed in range throughout.
540-
const maxSpeed = 2 * referenceSpeed;
541-
check(log).every((it) => it..isGreaterThan(0)..isLessThan(maxSpeed));
539+
// Check the main question: the speed was as expected throughout.
540+
check(log.slice(0, log.length-1)).every((it) => it.equals(maxSpeed));
541+
check(log).last..isGreaterThan(0)..isLessOrEqual(maxSpeed);
542+
542543
// Also check the test's assumptions: the scroll reached the end…
543544
check(pos).equals(0);
544545
// … and scrolled far enough to effectively test the max speed.

0 commit comments

Comments
 (0)