@@ -489,21 +489,23 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
489
489
}
490
490
491
491
void _modelChanged () {
492
- if (model! .narrow != widget.narrow) {
493
- // A message move event occurred, where propagate mode is
494
- // [PropagateMode.changeAll] or [PropagateMode.changeLater].
495
- widget.onNarrowChanged (model! .narrow);
496
- }
497
-
498
492
final previousLength = oldItems.length + newItems.length;
499
-
500
493
setState (() {
494
+ // Update both slivers with the new message positions
501
495
oldItems = model! .items.sublist (0 , model! .anchorIndex+ 1 );
502
496
newItems = model! .items.sublist (model! .anchorIndex+ 1 , model! .items.length);
503
497
// The actual state lives in the [MessageListView] model.
504
498
// This method was called because that just changed.
505
499
});
506
500
501
+ if (model! .narrow != widget.narrow) {
502
+ // A message move event occurred, where propagate mode is
503
+ // [PropagateMode.changeAll] or [PropagateMode.changeLater].
504
+ widget.onNarrowChanged (model! .narrow);
505
+ return ; // Let the parent widget handle the rebuild with new narrow
506
+ }
507
+
508
+
507
509
508
510
// Auto-scroll when new messages arrive if we're already near the bottom
509
511
if (model! .items.length > previousLength && // New messages were added
@@ -534,7 +536,6 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
534
536
36 , //Scroll 36 px inside bottomSliver.The sizedBox is 36px high. so theres no chance of overscrolling
535
537
duration: Duration (milliseconds: durationMs),
536
538
curve: Curves .easeIn);
537
- await Future <void >.delayed (const Duration (milliseconds: 50 ));
538
539
}
539
540
540
541
// Wait for the layout to settle so scrollController.position.pixels is updated properly
@@ -544,13 +545,12 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
544
545
// If we go too fast, we'll overscroll.as
545
546
546
547
// After scroling to the bottom sliver, scroll to the bottom of the bottomSliver if we're not already there
547
- while (distanceToBottom > 36 ) {
548
+ while (distanceToBottom > 36 && context.mounted ) {
548
549
await scrollController.animateTo (
549
550
scrollController.position.maxScrollExtent,
550
551
duration: Duration (milliseconds: durationMsToBottom),
551
552
curve: Curves .ease);
552
553
distanceToBottom = scrollController.position.maxScrollExtent - scrollController.position.pixels;
553
- await Future <void >.delayed (const Duration (milliseconds: 50 ));
554
554
}
555
555
556
556
}
@@ -781,7 +781,7 @@ class ScrollToBottomButton extends StatelessWidget {
781
781
final ValueNotifier <bool > visibleValue;
782
782
final ScrollController scrollController;
783
783
784
- Future <void > _navigateToBottom () async {
784
+ Future <void > _navigateToBottom (BuildContext context ) async {
785
785
// Calculate initial scroll parameters
786
786
final distanceToCenter = scrollController.position.pixels;
787
787
final durationMsAtSpeedLimit = (1000 * distanceToCenter / 8000 ).ceil ();
@@ -796,23 +796,18 @@ class ScrollToBottomButton extends StatelessWidget {
796
796
797
797
798
798
// Wait for the layout to settle so scrollController.position.pixels is updated properly
799
- await Future <void >.delayed (const Duration (milliseconds: 50 ));
800
799
801
800
var distanceToBottom = scrollController.position.maxScrollExtent - scrollController.position.pixels;
802
801
final durationMsToBottom = math.min (1000 , (1200 * distanceToBottom / 8000 ).ceil ());
803
802
// If we go too fast, we'll overscroll.
804
803
// After scroling to the bottom sliver, scroll to the bottom of the bottomSliver if we're not already there
805
- var count = 0 ;
806
- while (distanceToBottom > 36 ) {
804
+ while (distanceToBottom > 36 && context.mounted) {
807
805
await scrollController.animateTo (
808
806
scrollController.position.maxScrollExtent,
809
807
duration: Duration (milliseconds: durationMsToBottom),
810
808
curve: Curves .easeOut);
811
- await Future <void >.delayed (const Duration (milliseconds: 50 ));
812
809
distanceToBottom = scrollController.position.maxScrollExtent - scrollController.position.pixels;
813
- count++ ;
814
810
}
815
- print ("count: $count " );
816
811
}
817
812
818
813
@override
@@ -829,7 +824,7 @@ class ScrollToBottomButton extends StatelessWidget {
829
824
iconSize: 40 ,
830
825
// Web has the same color in light and dark mode.
831
826
color: const HSLColor .fromAHSL (0.5 , 240 , 0.96 , 0.68 ).toColor (),
832
- onPressed: _navigateToBottom));
827
+ onPressed: () => _navigateToBottom (context) ));
833
828
}
834
829
}
835
830
0 commit comments