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 sdk = SendbirdSdk().getInternal();
  final params = MessageListParams()
    ..previousResultSize = limit
    ..reverse = reverse
    ..customTypes = customTypesFilter
    ..messageType = messageTypeFilter
    ..senderIds = senderIdsFilter
    ..includeMetaArray = includeMetaArray
    ..includeParentMessageText = includeParentMessageText
    ..includeReactions = includeReactions
    ..includeReplies = includeReplies
    ..includeThreadInfo = includeThreadInfo
    ..showSubChannelMessagesOnly = showSubChannelMessagesOnly;

  final res = await sdk.api.getMessages(
      channelType: channelType,
      channelUrl: channelUrl,
      params: params.toJson(),
      timestamp: _timestamp);

  _timestamp = res.isNotEmpty ? res.last.createdAt : null;

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