Skip to content

Commit

Permalink
All test cases pass now
Browse files Browse the repository at this point in the history
  • Loading branch information
E-m-i-n-e-n-c-e committed Jan 23, 2025
1 parent b9b068c commit 2b6fa9e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
31 changes: 13 additions & 18 deletions lib/widgets/message_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -489,21 +489,23 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
}

void _modelChanged() {
if (model!.narrow != widget.narrow) {
// A message move event occurred, where propagate mode is
// [PropagateMode.changeAll] or [PropagateMode.changeLater].
widget.onNarrowChanged(model!.narrow);
}

final previousLength = oldItems.length + newItems.length;

setState(() {
// Update both slivers with the new message positions
oldItems = model!.items.sublist(0, model!.anchorIndex+1);
newItems = model!.items.sublist(model!.anchorIndex+1, model!.items.length);
// The actual state lives in the [MessageListView] model.
// This method was called because that just changed.
});

if (model!.narrow != widget.narrow) {
// A message move event occurred, where propagate mode is
// [PropagateMode.changeAll] or [PropagateMode.changeLater].
widget.onNarrowChanged(model!.narrow);
return; // Let the parent widget handle the rebuild with new narrow
}



// Auto-scroll when new messages arrive if we're already near the bottom
if (model!.items.length > previousLength && // New messages were added
Expand Down Expand Up @@ -534,7 +536,6 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
36, //Scroll 36 px inside bottomSliver.The sizedBox is 36px high. so theres no chance of overscrolling
duration: Duration(milliseconds: durationMs),
curve: Curves.easeIn);
await Future<void>.delayed(const Duration(milliseconds: 50));
}

// Wait for the layout to settle so scrollController.position.pixels is updated properly
Expand All @@ -544,13 +545,12 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
// If we go too fast, we'll overscroll.as

// After scroling to the bottom sliver, scroll to the bottom of the bottomSliver if we're not already there
while (distanceToBottom > 36) {
while (distanceToBottom > 36 && context.mounted) {
await scrollController.animateTo(
scrollController.position.maxScrollExtent,
duration: Duration(milliseconds: durationMsToBottom),
curve: Curves.ease);
distanceToBottom = scrollController.position.maxScrollExtent - scrollController.position.pixels;
await Future<void>.delayed(const Duration(milliseconds: 50));
}

}
Expand Down Expand Up @@ -781,7 +781,7 @@ class ScrollToBottomButton extends StatelessWidget {
final ValueNotifier<bool> visibleValue;
final ScrollController scrollController;

Future<void> _navigateToBottom() async {
Future<void> _navigateToBottom(BuildContext context) async {
// Calculate initial scroll parameters
final distanceToCenter = scrollController.position.pixels;
final durationMsAtSpeedLimit = (1000 * distanceToCenter / 8000).ceil();
Expand All @@ -796,23 +796,18 @@ class ScrollToBottomButton extends StatelessWidget {


// Wait for the layout to settle so scrollController.position.pixels is updated properly
await Future<void>.delayed(const Duration(milliseconds: 50));

var distanceToBottom = scrollController.position.maxScrollExtent - scrollController.position.pixels;
final durationMsToBottom = math.min(1000, (1200 * distanceToBottom / 8000).ceil());
// If we go too fast, we'll overscroll.
// After scroling to the bottom sliver, scroll to the bottom of the bottomSliver if we're not already there
var count = 0;
while (distanceToBottom > 36) {
while (distanceToBottom > 36 && context.mounted) {
await scrollController.animateTo(
scrollController.position.maxScrollExtent,
duration: Duration(milliseconds: durationMsToBottom),
curve: Curves.easeOut);
await Future<void>.delayed(const Duration(milliseconds: 50));
distanceToBottom = scrollController.position.maxScrollExtent - scrollController.position.pixels;
count++;
}
print("count: $count");
}

@override
Expand All @@ -829,7 +824,7 @@ class ScrollToBottomButton extends StatelessWidget {
iconSize: 40,
// Web has the same color in light and dark mode.
color: const HSLColor.fromAHSL(0.5, 240, 0.96, 0.68).toColor(),
onPressed: _navigateToBottom));
onPressed: () => _navigateToBottom(context)));
}
}

Expand Down
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1044,10 +1044,10 @@ packages:
dependency: transitive
description:
name: stream_channel
sha256: "4ac0537115a24d772c408a2520ecd0abb99bca2ea9c4e634ccbdbfae64fe17ec"
sha256: "969e04c80b8bcdf826f8f16579c7b14d780458bd97f56d107d3950fdbeef059d"
url: "https://pub.dev"
source: hosted
version: "2.1.3"
version: "2.1.4"
stream_transform:
dependency: transitive
description:
Expand Down

0 comments on commit 2b6fa9e

Please sign in to comment.