@@ -55,20 +55,7 @@ class FloatingDateDivider extends StatelessWidget {
5555 };
5656
5757 if (index == null ) return const Empty ();
58-
59- // We can only calculate the date divider if the element is a message
60- // widget and not one of the special items.
61-
62- // Parent Message
63- if (index == itemCount - 1 ) return const Empty ();
64- // Header Builder
65- if (index == itemCount - 2 ) return const Empty ();
66- // Top Loader Builder
67- if (index == itemCount - 3 ) return const Empty ();
68- // Bottom Loader Builder
69- if (index == 1 ) return const Empty ();
70- // Footer Builder
71- if (index == 0 ) return const Empty ();
58+ if (! _isValidMessageIndex (index)) return const Empty ();
7259
7360 // Offset the index to account for two extra items
7461 // (loader and footer) at the bottom of the ListView.
@@ -83,4 +70,16 @@ class FloatingDateDivider extends StatelessWidget {
8370 },
8471 );
8572 }
73+
74+ // Returns True if the item index is a valid message index and not one of the
75+ // special items (like header, footer, loaders, etc.).
76+ bool _isValidMessageIndex (int index) {
77+ if (index == itemCount - 1 ) return false ; // Parent Message
78+ if (index == itemCount - 2 ) return false ; // Header Builder
79+ if (index == itemCount - 3 ) return false ; // Top Loader Builder
80+ if (index == 1 ) return false ; // Bottom Loader Builder
81+ if (index == 0 ) return false ; // Footer Builder
82+
83+ return true ;
84+ }
8685}
0 commit comments