Skip to content

Commit

Permalink
fix: closes #447
Browse files Browse the repository at this point in the history
  • Loading branch information
lucien144 committed Jul 12, 2024
1 parent 38bb177 commit 545b7f6
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions lib/pages/last_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,17 @@ class _LastPageState extends State<LastPage> {

return DiscussionPageScaffold(
title: 'Poslední',
child: FutureBuilder(
future: ApiController().last(),
builder: (context, snapshot) {
if (snapshot.hasError) {
return T.feedbackScreen(context,
isWarning: true, title: snapshot.error.toString(), label: L.GENERAL_CLOSE, onPress: () => Navigator.of(context).pop());
} else if (snapshot.hasData) {
List posts = snapshot.data!.data['posts'];
return PullToRefreshList(
child: PullToRefreshList(
rebuild: _refreshData,
isInfinite: true,
dataProvider: (lastId) async {
int max = (lastId ?? 0) + 10;
max = max >= posts.length ? posts.length : max;
// For smoother transition
await Future.delayed(Duration(milliseconds: 300));

final response = await ApiController().last();
final posts = response.data['posts'];

List data = posts
.getRange(lastId ?? 0, max)
.map((post) => Post.fromJson(post, post['discussion_id'], isCompact: MainRepository().settings.useCompactMode))
.where((post) => !MainRepository().settings.isPostBlocked(post.id))
.where((post) => !MainRepository().settings.isUserBlocked(post.nick))
Expand Down Expand Up @@ -110,11 +104,8 @@ class _LastPageState extends State<LastPage> {
],
))
.toList();
return DataProviderResult(data, lastId: max);
return DataProviderResult(data);
},
);
}
return T.feedbackScreen(context, isLoading: true);
}));
));
}
}

0 comments on commit 545b7f6

Please sign in to comment.