Open tiltmaster opened 6 months ago
@tiltmaster, change the condition 'hasReachedMax: posts.length > 25' to 'hasReachedMax: posts.length < 25' and let me know if it works correctly.
@tiltmaster, change the condition 'hasReachedMax: posts.length > 25' to 'hasReachedMax: posts.length < 25' and let me know if it works correctly.
I actually have it as such, see the below code for example:
Future<void> fetchPosts({bool refresh = false}) async {
if (refresh) {
emit(state.invalidateSelf());
} else {
emit(state.copyWith(isLoading: true));
}
try {
const pageSize = 5;
late int start;
final end = state.page * pageSize;
if (state.page > 1) {
start = end - pageSize + 1;
} else {
start = end - pageSize;
}
final posts = await _fetchPosts(start: start, end: end);
final maxLength = await supa.Supabase.instance.client.from('posts').count().eq('is_deleted', false);
emit(state.copyWith(
isLoading: false,
posts: List.of(state.posts)..addAll(posts),
hasReachedMax: posts.length < maxLength,
page: state.page + 1,
hasError: false,
));
} catch (e) {
// If an error occurs, update the state with the hasError flag set to true.
emit(state.copyWith(isLoading: false, hasError: true));
}
}
Future<List<Posts>> _fetchPosts({
required int start,
required int end,
int limit = 5,
}) async {
try {
print('Start:$start End:$end');
final response = await supa.Supabase.instance.client.from('posts').select().eq('is_deleted', false).order('timestamp').range(start, end);
return response.map((dynamic json) => Posts.fromMap(json['id'], json)).toList();
} catch (e) {
throw Exception('Something went wrong while fetching posts');
}
}```
and its returning duplicates, the reason i did the start and end is to do pagination,
@tiltmaster, change the condition 'hasReachedMax: posts.length > 25' to 'hasReachedMax: posts.length < 25' and let me know if it works correctly.
When following ur example, and your suggestion, the hasReachedMax returns true. even tho that for example in the above shared code maxLength for example returns 50 posts, its returning true but its not because it has yet to be more than 50 posts
EDIT: I have solved this with state.posts.length >= maxLength,
So i have been trying your package and i have been facing issues, using your bloC example, i have been doing as such : however, im unable to get unique items and or new items to begin with, knowing that calling _fetchPosts is