loadNext method Null safety

  1. @override
Future<List<BaseMessage>> loadNext()
override

Load next items asynchronously

Implementation

@override
Future<List<BaseMessage>> loadNext() async {
  if (loading) throw QueryInProgressError();
  if (!hasNext) return [];

  loading = true;

  final params = MessageListParams()
    ..previousResultSize = limit
    ..reverse = reverse
    ..customTypes = customTypesFilter
    ..messageType = messageTypeFilter
    ..senderIds = senderIdsFilter
    ..includeMetaArray = includeMetaArray
    ..includeParentMessageInfo = includeParentMessageInfo
    ..includeParentMessageText = includeParentMessageText
    ..includeReactions = includeReactions
    ..includeThreadInfo = includeThreadInfo
    ..replyType = replyType
    ..includeReplies = includeReplies
    ..showSubChannelMessagesOnly = showSubChannelMessagesOnly;

  final sdk = SendbirdSdk().getInternal();
  final res = await sdk.api.send<List<BaseMessage>>(
    ChannelMessagesGetRequest(
      channelType: channelType,
      channelUrl: channelUrl,
      params: params.toJson(),
      timestamp: _timestamp ?? 0,
    ),
  );

  if (res.isNotEmpty) {
    final oldestMessage = reverse ? res.last : res.first;
    _timestamp = oldestMessage.createdAt;
  } else {
    _timestamp = null;
  }

  loading = false;
  hasNext = res.length == limit;
  return res;
}