You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"text": "FIRST UNSEEN\n\nVoluptatem voluptatum eos aut voluptatem occaecati. Quia ducimus vero molestiae molestiae illum illo nisi autem. Labore consectetur expedita illum consequatur inventore consequatur quasi voluptatem. Perspiciatis ut reprehenderit officiis animi voluptas.",
/// We need the index for auto scrolling because it will scroll until it reaches an index higher or equal that what it is scrolling towards. Index will be null for removed messages. Can just set to -1 for auto scroll.
456
+
Widget_messageBuilder(
457
+
Object object,
458
+
BoxConstraints constraints,
459
+
int? index,
460
+
) {
452
461
if (object isDateHeader) {
453
462
if (widget.dateHeaderBuilder !=null) {
454
463
return widget.dateHeaderBuilder!(object);
@@ -469,7 +478,7 @@ class ChatState extends State<Chat> {
469
478
} elseif (object isUnseenBanner) {
470
479
returnAutoScrollTag(
471
480
key:constKey('unseen_banner'),
472
-
index:_unseenMessageBannerIndex,
481
+
index:index ??-1,
473
482
controller: _scrollController,
474
483
child:constUnseenMessageBanner(),
475
484
);
@@ -483,9 +492,7 @@ class ChatState extends State<Chat> {
483
492
484
493
returnAutoScrollTag(
485
494
key:Key('scroll-${message.id}'),
486
-
// By using the hashCode as index we can jump to a message using its ID.
487
-
// Otherwise, we would have to keep track of a map from ID to index.
488
-
index: message.id.hashCode,
495
+
index: index ??-1,
489
496
controller: _scrollController,
490
497
child:Message(
491
498
avatarBuilder: widget.avatarBuilder,
@@ -531,6 +538,37 @@ class ChatState extends State<Chat> {
531
538
}
532
539
}
533
540
541
+
/// Updates the [_autoScrollIndexByID] mapping with the latest messages.
542
+
void_refreshAutoScrollMapping() {
543
+
_autoScrollIndexByID.clear();
544
+
var i =0;
545
+
for (final object in _chatMessages) {
546
+
if (object isUnseenBanner) {
547
+
_autoScrollIndexByID[_unseenMessageBannerID] = i;
548
+
} elseif (object isMap<String, Object>) {
549
+
final message = object['message']!as types.Message;
550
+
_autoScrollIndexByID[message.id] = i;
551
+
}
552
+
i++;
553
+
}
554
+
}
555
+
556
+
/// Only scroll to first unseen if there are messages and it is the first open.
0 commit comments