스크롤 중에 데이터를 점진적으로 로드할 수 있도록 ListView 위젯을 확장하는 플러터 패키지입니다. 사용자가 리스트의 끝에 다가갈 때 자동으로 데이터를 가져오므로 성능 부하 없이 대규모 데이터 세트를 처리하는 데 이상적입니다. 이 패키지는 스크롤 이벤트와 로딩 상태를 원활하게 관리하여 페이징 로직을 단순화합니다. 사용자 정의 로딩 인디케이터 및 오류 처리를 지원해 원활한 사용자 경험을 보장합니다. 최소한의 보일러플레이트로 효율적인 즉시 사용 가능한 지연 로딩을 원하는 개발자를 위한 것입니다.
사용 사례
실시간으로 대규모 데이터셋 로드
무한 스크롤 피드 구현
페이지네이션된 API 결과 가져오기
채팅 또는 타임라인 인터페이스 구축
긴 목록에서 성능 향상
주요 기능
자동 스크롤 데이터 로딩
사용자 정의 가능한 로딩 인디케이터
내장 오류 처리
기존 ListView와의 간편한 통합
정방향 및 역방향 페이지네이션을 지원
적합한 대상
동적 콘텐츠 피드를 구축하는 개발자
광범위한 데이터 목록을 가진 앱
부드러운 스크롤 성능이 필요한 프로젝트
페이지네이션 보일러플레이트를 줄이고자 하는 팀
네트워크에 의존하는 데이터를 가진 모바일 앱
고려 사항
적절한 상태 관리가 필요합니다
복잡한 로딩 로직을 위해 맞춤 설정이 필요할 수 있습니다
매우 높은 빈도의 업데이트에 최적화되지 않음
제한된 플랫폼별 최적화
완전한 기능을 위해 외부 종속성에 의존합니다
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
incrementally_loading_listview
An extension of the Flutter ListView widget for incrementally loading items upon scrolling. This could be used to load paginated data received from API requests.
NOTE: this package depends on rxdart. If you run into conflicts with different versions of rxdart, consider using dependency overrides as per this link
Getting Started
There's a working example that can be run to see how it works.
You can then use the IncrementallyLoadingListView widget in a similar way you would with the ListView.separated constructor
returnIncrementallyLoadingListView(
hasMore: () => _hasMoreItems,
itemCount: () => items.length,
loadMore: () async {
// can shorten to "loadMore: _loadMoreItems" but this syntax is used to demonstrate that// functions with parameters can also be invoked if neededawait_loadMoreItems();
},
loadMoreOffsetFromBottom: 2,
itemBuilder: (context, index) {
/// your builder function for rendering the item
},
separatorBuilder: (context, index) {
/// your builder function for rendering the separator
}
);
The widget allows passing in the same parameters you would to the ListView.builder constructor but itemCount is required so that when an item scrolls into view, it can see if it should attempt to load more items. Note that this is a callback that returns a boolean rather than being a boolean value. This allows the widget to not require a reference/copy of your data collection. The other parameters that can be specified are
hasMore: a callback that indicates if there are more items that can be loaded
loadMore: a callback to an asynchronous function that loads more items
loadMoreOffsetFromBottom: determines when the list view should attempt to load more items based on of the index of the item is scrolling into view. This is relative to the bottom of the list and has a default value of 0 so that it loads when the last item within the list view scrolls into view. As an example, setting this to 1 would attempt to load more items when the second last item within the list view scrolls into view
onLoadMore: a callback that is triggered when more items are being loaded. At first this will pass a boolean value of true to when items are being loaded by triggering the loadMore callback function. You could use this to update your UI to show a loading indicator
onLoadMoreFinished: a callback that is triggered when items have finished being loading. You can use this to hide your loading indicator
separatorBuilder: not required builder function that place separator between items
Providing onLoadMore and onLoadMoreFinished callbacks means the widget doesn't make assumptions on how you want to render a loading indicator so it will be up to your application to handle these callbacks to render the appropriate UI.