From 6fc336223b84f476becf4c9ab499b4b3a4f7941c Mon Sep 17 00:00:00 2001 From: kolaente Date: Wed, 15 Jan 2020 23:33:33 +0100 Subject: [PATCH] Format --- lib/api/client.dart | 4 +++- lib/pages/list/list.dart | 47 +++++++++++++++++++++++----------------- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/lib/api/client.dart b/lib/api/client.dart index ed44640..670640c 100644 --- a/lib/api/client.dart +++ b/lib/api/client.dart @@ -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); } } diff --git a/lib/pages/list/list.dart b/lib/pages/list/list.dart index a683890..8b9cf29 100644 --- a/lib/pages/list/list.dart +++ b/lib/pages/list/list.dart @@ -56,27 +56,31 @@ class _ListPageState extends State { ? 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 { } Future _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);