fetchNext method
Future<List<Conversation> >
fetchNext({
- required dynamic onSuccess(
- List<
Conversation> message
- List<
- required dynamic onError(
- CometChatException excep
Returns a list of Conversation object fetched after putting the filters.
Implementation
Future<List<Conversation>> fetchNext(
{required Function(List<Conversation> message)? onSuccess,
required Function(CometChatException excep)? onError}) async {
try {
final result = await channel.invokeMethod('fetchNextConversations', {
'limit': this.limit,
'type': this.conversationType,
'init': this.init,
'withUserAndGroupTags': withUserAndGroupTags,
'withTags': this.withTags,
'tags': this.tags,
'key': this.key,
'includeBlockedUsers': this.includeBlockedUsers,
'withBlockedInfo': this.withBlockedInfo
});
final List<Conversation> res = [];
if (result != null) {
key = result["key"];
debugPrint("key is $key");
if (result["list"] != null) {
for (var _obj in result["list"]) {
try {
res.add(Conversation.fromMap(_obj));
} catch (e) {
if (onError != null) {
onError(CometChatException(ErrorCode.errorUnhandledException,
e.toString(), e.toString()));
}
return [];
}
}
}
}
if (onSuccess != null) {
onSuccess(res);
}
this.init = false;
return res;
} on PlatformException catch (platformException) {
if (onError != null) {
onError(CometChatException(platformException.code,
platformException.details, platformException.message));
}
} catch (e) {
debugPrint("Error: $e");
if (onError != null) {
onError(CometChatException(
ErrorCode.errorUnhandledException, e.toString(), e.toString()));
}
}
return [];
}