Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ingvilow
Copy link
Owner

        * Логика по определению какую именно порцию данных необходимо загружать должна быть в слое модели.
        * При возникновении ошибки должен показаться снекбар с сообщением, список уже загруженных мест не должен пропасть

            * Логика по определению какую именно порцию данных необходимо загружать должна быть в слое модели.
            * При возникновении ошибки должен показаться снекбар с сообщением, список уже загруженных мест не должен пропасть
@ingvilow ingvilow requested a review from maxim-sysoev June 29, 2022 09:53
@ingvilow ingvilow self-assigned this Jun 29, 2022
Comment on lines 76 to 78
final nextPlace = await model.getNextPlaceItem();
if (nextPlace.isNotEmpty) {
_currentPlaceState.loading(_currentPlaceState.value?.data);

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++);

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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

в случае ошибки при пагинации должен появиться снэк, не полноэкранная ошибка
полноэкранная ошибка появляется только в случае первой загрузки при открытии экрана

Comment on lines 35 to 62
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],

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();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

загрузка новых мест не должна начинаться если сейчас выполняется обновление

ingvilow added 2 commits June 30, 2022 11:28
…щением, список уже загруженных мест не должен пропасть + полноэкранная ошибка при первой загрузке
…щением, список уже загруженных мест не должен пропасть + полноэкранная ошибка при первой загрузке
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants