-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SPO-13135 - * Реализовать запрос для загрузки новых мест #12
base: main
Are you sure you want to change the base?
Conversation
ingvilow
commented
Jun 29, 2022
* Логика по определению какую именно порцию данных необходимо загружать должна быть в слое модели. * При возникновении ошибки должен показаться снекбар с сообщением, список уже загруженных мест не должен пропасть
final nextPlace = await model.getNextPlaceItem(); | ||
if (nextPlace.isNotEmpty) { | ||
_currentPlaceState.loading(_currentPlaceState.value?.data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
получается у нас выполняется запрос, мы смотрим на его результат:
- если он не пустой, то мы на мгновение включаем состояние загрузки и сразу ставим состояние загруженного контента (даже один кадр с лоадером показаться не успеет)
- если из запроса вернулся пустой список, то ничего не делаем
зачем это и чем помогает?
|
||
/// загрузить следующие элементы из списка | ||
Future<List<Place>> getNextPlaceItem() { | ||
return _getPlace(currentPage++); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
увеличить currentPage
надо только если запрос прошёл успешно и не было ошибок
} | ||
} on Exception catch (err) { | ||
_currentPlaceState.error(err); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
в случае ошибки при пагинации должен появиться снэк, не полноэкранная ошибка
полноэкранная ошибка появляется только в случае первой загрузки при открытии экрана
if (placesPaginated?.isEmpty ?? true) { | ||
return const AnimateLoader(); | ||
} | ||
return RefreshIndicator( | ||
onRefresh: wm.onRefresh, | ||
child: ListView.builder( | ||
controller: wm.scrollController, | ||
itemCount: placesPaginated!.length + 1, | ||
itemBuilder: (context, index) { | ||
if (index == placesPaginated.length) { | ||
return const Center(child: CircularProgressIndicator()); | ||
} | ||
return ListPlaceElement( | ||
place: placesPaginated[index], | ||
); | ||
}, | ||
), | ||
); | ||
}, | ||
builder: (_, place) { | ||
return RefreshIndicator( | ||
onRefresh: wm.onRefresh, | ||
child: ListView.builder( | ||
itemCount: place!.length, | ||
controller: wm.scrollController, | ||
itemCount: place?.length ?? 0, | ||
itemBuilder: (context, index) { | ||
return ListPlaceElement( | ||
place: place[index], | ||
place: place![index], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
для вёрстки есть отдельная задача
void _onScroll() { | ||
if (scrollController.position.pixels >= | ||
scrollController.position.maxScrollExtent) { | ||
_loadPlaces(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
загрузка новых мест не должна начинаться если сейчас выполняется обновление
…щением, список уже загруженных мест не должен пропасть + полноэкранная ошибка при первой загрузке
…щением, список уже загруженных мест не должен пропасть + полноэкранная ошибка при первой загрузке