Re-implemented getting tasks with the new seperate endpoint #39
|
@ -8,6 +8,7 @@ class Client {
|
|||
final String _token;
|
||||
final String _base;
|
||||
int _maxPages;
|
||||
|
||||
int get maxPages => _maxPages;
|
||||
|
||||
String get base => _base;
|
||||
|
@ -38,8 +39,8 @@ class Client {
|
|||
port: uri.port,
|
||||
path: uri.path,
|
||||
query: uri.query,
|
||||
queryParameters:
|
||||
queryParameters, // Because dart takes a Map<String, String> here, it is only possible to sort by one parameter while the api supports n parameters.
|
||||
queryParameters: queryParameters,
|
||||
// Because dart takes a Map<String, String> here, it is only possible to sort by one parameter while the api supports n parameters.
|
||||
fragment: uri.fragment);
|
||||
return http.get(newUri, headers: _headers).then(_handleResponse);
|
||||
}
|
||||
|
@ -71,9 +72,16 @@ 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;
|
||||
// FIXME: This is a workaround for when the client makes another
|
||||
// unrelated api request in between requesting multiple pages of the same thing.
|
||||
// To properly fix this, we need a way to pass the max number of pages somewhere else
|
||||
// and not save them in the global client which everyone uses.
|
||||
// This workaround only works when the other api requests in between two pages
|
||||
// are not using pagination.
|
||||
if (response.headers["x-pagination-total-pages"] != null) {
|
||||
_maxPages = int.parse(response.headers["x-pagination-total-pages"]);
|
||||
}
|
||||
|
||||
return _decoder.convert(response.body);
|
||||
}
|
||||
}
|
||||
|
@ -81,6 +89,7 @@ class Client {
|
|||
class ApiException implements Exception {
|
||||
final int errorCode;
|
||||
|
||||
final String path;
|
||||
|
||||
ApiException(this.errorCode, this.path);
|
||||
|
||||
@override
|
||||
|
|
|
@ -73,10 +73,6 @@ class _ListPageState extends State<ListPage> {
|
|||
.taskService
|
||||
.maxPages) {
|
||||
_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 index < _tasks.length
|
||||
|
|
Reference in New Issue
Please save this in stores. This shouldn't be handled by the client.
Done!