mirror of
https://github.com/git-touch/git-touch
synced 2025-01-27 06:14:53 +01:00
fix: remove loading when reach to end
This commit is contained in:
parent
66c040e523
commit
6933c04472
@ -8,9 +8,9 @@ import '../widgets/loading.dart';
|
||||
class ListPayload<T, K> {
|
||||
K cursor;
|
||||
List<T> items;
|
||||
bool end;
|
||||
bool hasMore;
|
||||
|
||||
ListPayload({this.items, this.cursor, this.end});
|
||||
ListPayload({this.items, this.cursor, this.hasMore});
|
||||
}
|
||||
|
||||
// This is a scaffold for infinite scroll screens
|
||||
@ -42,7 +42,7 @@ class _ListScaffoldState<T, K> extends State<ListScaffold<T, K>> {
|
||||
|
||||
List<T> items = [];
|
||||
K cursor;
|
||||
bool end;
|
||||
bool hasMore;
|
||||
|
||||
ScrollController _controller = ScrollController();
|
||||
|
||||
@ -54,7 +54,8 @@ class _ListScaffoldState<T, K> extends State<ListScaffold<T, K>> {
|
||||
if (_controller.offset + 100 > _controller.position.maxScrollExtent &&
|
||||
!_controller.position.outOfRange &&
|
||||
!loading &&
|
||||
!loadingMore) {
|
||||
!loadingMore &&
|
||||
hasMore) {
|
||||
_loadMore();
|
||||
}
|
||||
});
|
||||
@ -70,7 +71,7 @@ class _ListScaffoldState<T, K> extends State<ListScaffold<T, K>> {
|
||||
var _payload = await widget.onRefresh();
|
||||
items = _payload.items;
|
||||
cursor = _payload.cursor;
|
||||
end = _payload.end;
|
||||
hasMore = _payload.hasMore;
|
||||
} catch (err) {
|
||||
// print(err);
|
||||
error = err.toString();
|
||||
@ -92,7 +93,7 @@ class _ListScaffoldState<T, K> extends State<ListScaffold<T, K>> {
|
||||
var _payload = await widget.onLoadMore(cursor);
|
||||
items.addAll(_payload.items);
|
||||
cursor = _payload.cursor;
|
||||
end = _payload.end;
|
||||
hasMore = _payload.hasMore;
|
||||
} catch (err) {
|
||||
print(err);
|
||||
} finally {
|
||||
@ -106,7 +107,11 @@ class _ListScaffoldState<T, K> extends State<ListScaffold<T, K>> {
|
||||
|
||||
Widget _buildItem(BuildContext context, int index) {
|
||||
if (index == 2 * items.length) {
|
||||
return Loading(more: true);
|
||||
if (hasMore) {
|
||||
return Loading(more: true);
|
||||
} else {
|
||||
return Container();
|
||||
}
|
||||
}
|
||||
|
||||
if (index % 2 == 1) {
|
||||
|
@ -14,8 +14,8 @@ class NewsScreenState extends State<NewsScreen> {
|
||||
Future<List<Event>> fetchEvents(int page) async {
|
||||
var settings = SettingsProvider.of(context);
|
||||
var login = settings.activeLogin;
|
||||
List data = await settings
|
||||
.getWithCredentials('/users/$login/received_events?page=$page');
|
||||
List data = await settings.getWithCredentials(
|
||||
'/users/$login/received_events?page=$page&per_page=$pageSize');
|
||||
// print(data);
|
||||
return data.map<Event>((item) => Event.fromJSON(item)).toList();
|
||||
}
|
||||
@ -31,12 +31,12 @@ class NewsScreenState extends State<NewsScreen> {
|
||||
var page = 1;
|
||||
var items = await fetchEvents(page);
|
||||
return ListPayload(
|
||||
cursor: page + 1, end: items.length < 30, items: items);
|
||||
cursor: page + 1, hasMore: items.length == pageSize, items: items);
|
||||
},
|
||||
onLoadMore: (page) async {
|
||||
var items = await fetchEvents(page);
|
||||
return ListPayload(
|
||||
cursor: page + 1, end: items.length < 30, items: items);
|
||||
cursor: page + 1, hasMore: items.length == pageSize, items: items);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ class _ReposScreenState extends State<ReposScreen> {
|
||||
return ListPayload(
|
||||
cursor: repo["pageInfo"]["endCursor"],
|
||||
items: repo["nodes"],
|
||||
end: repo['pageInfo']['hasNextPage'],
|
||||
hasMore: repo['pageInfo']['hasNextPage'],
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ class _UsersScreenState extends State<UsersScreen> {
|
||||
|
||||
return ListPayload(
|
||||
cursor: repo["pageInfo"]["endCursor"],
|
||||
end: repo['pageInfo']['hasNextPage'],
|
||||
hasMore: repo['pageInfo']['hasNextPage'],
|
||||
items: repo["nodes"],
|
||||
);
|
||||
}
|
||||
|
@ -155,7 +155,7 @@ class Palette {
|
||||
static const gray = Color(0xff959da5);
|
||||
}
|
||||
|
||||
final pageSize = 20;
|
||||
final pageSize = 30;
|
||||
|
||||
final graphqlChunk1 = '''
|
||||
title
|
||||
|
Loading…
Reference in New Issue
Block a user