@@ -448,8 +448,11 @@ class MessageList extends StatefulWidget {
448
448
}
449
449
450
450
class _MessageListState extends State <MessageList > with PerAccountStoreAwareStateMixin <MessageList > {
451
- MessageListView ? model;
451
+ MessageListView get model => _model! ;
452
+ MessageListView ? _model;
453
+
452
454
final MessageListScrollController scrollController = MessageListScrollController ();
455
+
453
456
final ValueNotifier <bool > _scrollToBottomVisible = ValueNotifier <bool >(false );
454
457
455
458
@override
@@ -460,32 +463,32 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
460
463
461
464
@override
462
465
void onNewStore () { // TODO(#464) try to keep using old model until new one gets messages
463
- model ? .dispose ();
466
+ _model ? .dispose ();
464
467
_initModel (PerAccountStoreWidget .of (context));
465
468
}
466
469
467
470
@override
468
471
void dispose () {
469
- model ? .dispose ();
472
+ _model ? .dispose ();
470
473
scrollController.dispose ();
471
474
_scrollToBottomVisible.dispose ();
472
475
super .dispose ();
473
476
}
474
477
475
478
void _initModel (PerAccountStore store) {
476
- model = MessageListView .init (store: store, narrow: widget.narrow);
477
- model! .addListener (_modelChanged);
478
- model! .fetchInitial ();
479
+ _model = MessageListView .init (store: store, narrow: widget.narrow);
480
+ model.addListener (_modelChanged);
481
+ model.fetchInitial ();
479
482
}
480
483
481
484
void _modelChanged () {
482
- if (model! .narrow != widget.narrow) {
485
+ if (model.narrow != widget.narrow) {
483
486
// Either:
484
487
// - A message move event occurred, where propagate mode is
485
488
// [PropagateMode.changeAll] or [PropagateMode.changeLater]. Or:
486
489
// - We fetched a "with" / topic-permalink narrow, and the response
487
490
// redirected us to the new location of the operand message ID.
488
- widget.onNarrowChanged (model! .narrow);
491
+ widget.onNarrowChanged (model.narrow);
489
492
}
490
493
setState (() {
491
494
// The actual state lives in the [MessageListView] model.
@@ -507,7 +510,7 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
507
510
// but makes things a bit more complicated to reason about.
508
511
// The cause seems to be that this gets called again with maxScrollExtent
509
512
// still not yet updated to account for the newly-added messages.
510
- model! .fetchOlder ();
513
+ model.fetchOlder ();
511
514
}
512
515
}
513
516
@@ -528,8 +531,7 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
528
531
529
532
@override
530
533
Widget build (BuildContext context) {
531
- assert (model != null );
532
- if (! model! .fetched) return const Center (child: CircularProgressIndicator ());
534
+ if (! model.fetched) return const Center (child: CircularProgressIndicator ());
533
535
534
536
// Pad the left and right insets, for small devices in landscape.
535
537
return SafeArea (
@@ -571,9 +573,9 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
571
573
572
574
// The list has two slivers: a top sliver growing upward,
573
575
// and a bottom sliver growing downward.
574
- // Each sliver has some of the items from `model! .items`.
576
+ // Each sliver has some of the items from `model.items`.
575
577
const maxBottomItems = 1 ;
576
- final totalItems = model! .items.length;
578
+ final totalItems = model.items.length;
577
579
final bottomItems = totalItems <= maxBottomItems ? totalItems : maxBottomItems;
578
580
final topItems = totalItems - bottomItems;
579
581
@@ -599,7 +601,7 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
599
601
// and will not trigger this callback.
600
602
findChildIndexCallback: (Key key) {
601
603
final messageId = (key as ValueKey <int >).value;
602
- final itemIndex = model! .findItemWithMessageId (messageId);
604
+ final itemIndex = model.findItemWithMessageId (messageId);
603
605
if (itemIndex == - 1 ) return null ;
604
606
final childIndex = totalItems - 1 - (itemIndex + bottomItems);
605
607
if (childIndex < 0 ) return null ;
@@ -608,7 +610,7 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
608
610
childCount: topItems,
609
611
(context, childIndex) {
610
612
final itemIndex = totalItems - 1 - (childIndex + bottomItems);
611
- final data = model! .items[itemIndex];
613
+ final data = model.items[itemIndex];
612
614
final item = _buildItem (zulipLocalizations, data);
613
615
return item;
614
616
}));
@@ -637,7 +639,7 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
637
639
// and will not trigger this callback.
638
640
findChildIndexCallback: (Key key) {
639
641
final messageId = (key as ValueKey <int >).value;
640
- final itemIndex = model! .findItemWithMessageId (messageId);
642
+ final itemIndex = model.findItemWithMessageId (messageId);
641
643
if (itemIndex == - 1 ) return null ;
642
644
final childIndex = itemIndex - topItems;
643
645
if (childIndex < 0 ) return null ;
@@ -654,7 +656,7 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
654
656
if (childIndex == bottomItems) return TypingStatusWidget (narrow: widget.narrow);
655
657
656
658
final itemIndex = topItems + childIndex;
657
- final data = model! .items[itemIndex];
659
+ final data = model.items[itemIndex];
658
660
return _buildItem (zulipLocalizations, data);
659
661
}));
660
662
0 commit comments