본문 바로가기

개발/Flutter

Infinite Scroll ListView

Infinite Scroll ListView

overall : 무한스크롤 리스트뷰
author : huansuh
draft : 2019.11.13


ListView widget을 통해 아래와 같이 무한스크롤을 구현할 수 있다.

ListView.builder(
    itemCount: itemList.length + 1,    // 실제 데이터수 + 1
    itemBuilder: (context, idx) {
        // 최하단 체크
        if(idx == itemCount) {
            // 데이터 요청 여부(end of data) 체크
            if(canLoadMore() == true) {
                loadMore();    // 추가 데이터 요청

                // 로딩 프로그레스 return
                return Center(
                    child: Padding(
                        padding: const EdgeInsets.all(16.0),
                        child: CircularProgressIndicator(),
                    ),
                );
            } else {
                // 더 이상 데이터를 요청하지 않을 시 공백 Conatiner return
                return Container();
            }
        }
        return _buildItemRow(itemList[idx]); //  실제 개별 item view
    }
)

'개발 > Flutter' 카테고리의 다른 글

State, Stateful&Stateless Widget  (0) 2019.11.25
JSON and serialization  (0) 2019.11.20
Flutter State management 개요  (0) 2019.11.20