refactor(ui): make initialIndex, initialAlignment non nullable
Signed-off-by: xsahil03x <[email protected]>
This commit is contained in:
@@ -298,8 +298,9 @@ class _MessageListViewState extends State<MessageListView> {
|
|||||||
StreamChannelState? streamChannel;
|
StreamChannelState? streamChannel;
|
||||||
late StreamChatThemeData _streamTheme;
|
late StreamChatThemeData _streamTheme;
|
||||||
|
|
||||||
int? get _initialIndex {
|
int get _initialIndex {
|
||||||
if (widget.initialScrollIndex != null) return widget.initialScrollIndex;
|
final initialScrollIndex = widget.initialScrollIndex;
|
||||||
|
if (initialScrollIndex != null) return initialScrollIndex;
|
||||||
if (streamChannel!.initialMessageId != null) {
|
if (streamChannel!.initialMessageId != null) {
|
||||||
final messages = streamChannel!.channel.state!.messages;
|
final messages = streamChannel!.channel.state!.messages;
|
||||||
final totalMessages = messages.length;
|
final totalMessages = messages.length;
|
||||||
@@ -312,8 +313,9 @@ class _MessageListViewState extends State<MessageListView> {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
double? get _initialAlignment {
|
double get _initialAlignment {
|
||||||
if (widget.initialAlignment != null) return widget.initialAlignment;
|
final initialAlignment = widget.initialAlignment;
|
||||||
|
if (initialAlignment != null) return initialAlignment;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -326,8 +328,8 @@ class _MessageListViewState extends State<MessageListView> {
|
|||||||
bool _topPaginationActive = false;
|
bool _topPaginationActive = false;
|
||||||
bool _bottomPaginationActive = false;
|
bool _bottomPaginationActive = false;
|
||||||
|
|
||||||
int? initialIndex;
|
int initialIndex = 0;
|
||||||
double? initialAlignment;
|
double initialAlignment = 0;
|
||||||
|
|
||||||
List<Message> messages = <Message>[];
|
List<Message> messages = <Message>[];
|
||||||
|
|
||||||
@@ -454,14 +456,12 @@ class _MessageListViewState extends State<MessageListView> {
|
|||||||
_inBetweenList = true;
|
_inBetweenList = true;
|
||||||
},
|
},
|
||||||
child: ScrollablePositionedList.separated(
|
child: ScrollablePositionedList.separated(
|
||||||
key: (_upToDate ||
|
key: _upToDate
|
||||||
initialIndex == null ||
|
|
||||||
initialAlignment == null)
|
|
||||||
? null
|
? null
|
||||||
: ValueKey(initialIndex! + initialAlignment!),
|
: ValueKey(initialIndex + initialAlignment),
|
||||||
itemPositionsListener: _itemPositionListener,
|
itemPositionsListener: _itemPositionListener,
|
||||||
initialScrollIndex: initialIndex ?? 0,
|
initialScrollIndex: initialIndex,
|
||||||
initialAlignment: initialAlignment ?? 0,
|
initialAlignment: initialAlignment,
|
||||||
physics: widget.scrollPhysics,
|
physics: widget.scrollPhysics,
|
||||||
itemScrollController: _scrollController,
|
itemScrollController: _scrollController,
|
||||||
reverse: widget.reverse,
|
reverse: widget.reverse,
|
||||||
@@ -1199,12 +1199,10 @@ class _MessageListViewState extends State<MessageListView> {
|
|||||||
initialAlignment = _initialAlignment;
|
initialAlignment = _initialAlignment;
|
||||||
|
|
||||||
WidgetsBinding.instance!.addPostFrameCallback((timeStamp) {
|
WidgetsBinding.instance!.addPostFrameCallback((timeStamp) {
|
||||||
if (initialIndex != null) {
|
_scrollController?.jumpTo(
|
||||||
_scrollController?.jumpTo(
|
index: initialIndex,
|
||||||
index: initialIndex!,
|
alignment: initialAlignment,
|
||||||
alignment: initialAlignment ?? 0,
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
_messageNewListener =
|
_messageNewListener =
|
||||||
|
|||||||
Reference in New Issue
Block a user