forked from vikunja/app
Format
This commit is contained in:
parent
b5363cb6ac
commit
6fc336223b
|
@ -71,7 +71,9 @@ class Client {
|
|||
throw new ApiException(
|
||||
response.statusCode, response.request.url.toString());
|
||||
}
|
||||
_maxPages = response.headers["x-pagination-total-pages"] != null ? int.parse(response.headers["x-pagination-total-pages"]) : 0;
|
||||
_maxPages = response.headers["x-pagination-total-pages"] != null
|
||||
? int.parse(response.headers["x-pagination-total-pages"])
|
||||
: 0;
|
||||
return _decoder.convert(response.body);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,27 +56,31 @@ class _ListPageState extends State<ListPage> {
|
|||
? RefreshIndicator(
|
||||
child: _tasks.length > 0
|
||||
? ListView.builder(
|
||||
padding: EdgeInsets.symmetric(vertical: 8.0),
|
||||
itemBuilder: (context, i) {
|
||||
if (i.isOdd) return Divider();
|
||||
padding: EdgeInsets.symmetric(vertical: 8.0),
|
||||
itemBuilder: (context, i) {
|
||||
if (i.isOdd) return Divider();
|
||||
|
||||
final index = i ~/ 2;
|
||||
final index = i ~/ 2;
|
||||
|
||||
// This handles the case if there are no more elements in the list left which can be provided by the api
|
||||
if(VikunjaGlobal.of(context).taskService.maxPages == _currentPage && index == _tasks.length - 1) return null;
|
||||
// This handles the case if there are no more elements in the list left which can be provided by the api
|
||||
if (VikunjaGlobal.of(context).taskService.maxPages ==
|
||||
_currentPage &&
|
||||
index == _tasks.length - 1) return null;
|
||||
|
||||
if (index >= _tasks.length && VikunjaGlobal.of(context).taskService.maxPages < _currentPage) {
|
||||
_currentPage++;
|
||||
// FIXME: This does not get loaded until some time after the next (_tasks.length + 1) entry should have been rendered
|
||||
// This leads to errors because the render method tries to access an entry of _tasks with an index which does not exist
|
||||
// The load function gets actually called after the return below. I assume this is because of the setState() invocation
|
||||
// in _loadTasksForPage()?
|
||||
_loadTasksForPage(_currentPage);
|
||||
}
|
||||
return TaskTile(
|
||||
task: _tasks[index],
|
||||
);
|
||||
})
|
||||
if (index >= _tasks.length &&
|
||||
VikunjaGlobal.of(context).taskService.maxPages <
|
||||
_currentPage) {
|
||||
_currentPage++;
|
||||
// FIXME: This does not get loaded until some time after the next (_tasks.length + 1) entry should have been rendered
|
||||
// This leads to errors because the render method tries to access an entry of _tasks with an index which does not exist
|
||||
// The load function gets actually called after the return below. I assume this is because of the setState() invocation
|
||||
// in _loadTasksForPage()?
|
||||
_loadTasksForPage(_currentPage);
|
||||
}
|
||||
return TaskTile(
|
||||
task: _tasks[index],
|
||||
);
|
||||
})
|
||||
: Center(child: Text('This list is empty.')),
|
||||
onRefresh: _loadList,
|
||||
)
|
||||
|
@ -118,8 +122,11 @@ class _ListPageState extends State<ListPage> {
|
|||
}
|
||||
|
||||
Future<void> _loadTasksForPage(int page) {
|
||||
return VikunjaGlobal.of(context).taskService.getAll(
|
||||
_list.id, {"sort_by": "done", "order_by": "asc", "page": page.toString()}).then((tasks) {
|
||||
return VikunjaGlobal.of(context).taskService.getAll(_list.id, {
|
||||
"sort_by": "done",
|
||||
"order_by": "asc",
|
||||
"page": page.toString()
|
||||
}).then((tasks) {
|
||||
setState(() {
|
||||
_loading = false;
|
||||
_tasks.addAll(tasks);
|
||||
|
|
Loading…
Reference in New Issue