패키지, 저장소 및 앱 카테고리 검색

very_good_infinite_list 표지
패키지 상세v0.9.0

very_good_infinite_list

Very Good Ventures에서 만든 페이지 단위 데이터를 쉽게 표시할 수 있는 라이브러리입니다. 활동 피드, 뉴스 피드 등에 적합합니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
1.5만
좋아요
309
Pub 점수
150

패키지 설치

flutter pub add very_good_infinite_list

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

Very Good Ventures에서 만든 Flutter 패키지로, 뉴스 피드나 활동 스트림과 같은 무한 스크롤 인터페이스에 적합한 페이지네이션 리스트 구현을 간소화합니다. 최소한의 부가 코드로 로딩 상태, 오류 복구, 자동 페이지 전환을 처리합니다. 성능과 개발자 경험을 고려해 설계되었으며, 지연 로딩 데이터를 필요로 하는 앱에 원활하게 통합됩니다.

사용 사례

  • 무한 스크롤 피드
  • 뉴스 및 블로그 목록
  • 활동 시간선
  • 사용자 생성 콘텐츠 스트림
  • 전자상거래 제품 그리드

주요 기능

  • 자동 페이지네이션 처리
  • 내장된 로딩 및 오류 상태
  • 최소 설정으로 간단한 API
  • 풀 투 리프레시를 지원합니다
  • 성능 최적화

적합한 대상

  • 피드 기반 앱을 개발하는 개발자
  • 빠른 UI 개발을 우선시하는 팀
  • 부드러운 무한 스크롤이 필요한 프로젝트
  • 대규모 데이터셋을 가진 앱
  • 신뢰할 수 있는 페이지네이션을 찾는 Flutter 초보자

고려 사항

  • 페이지 기반 가져오기 기능을 지원하는 데이터 소스가 필요합니다
  • 복잡한 스크롤 동작에 대한 사용자 정의 제한
  • 리스트가 아닌 스크롤 가능한 위젯용으로 설계되지 않음
  • 외부 상태 관리에 의존
  • 필터링 또는 정렬을 위해 추가적인 로직이 필요할 수 있습니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

Very Good Infinite List

Very Good Ventures Very Good Ventures

Developed with 💙 by Very Good Ventures 🦄

ci coverage pub package License: MIT style: very good analysis

[!NOTE] There is an active proposal to integrate this package's functionality directly into the Flutter framework. Follow the conversation and share your feedback in flutter/flutter#177451.


A library for easily displaying paginated data, created by Very Good Ventures.

InfiniteList comes in handy when building features like activity feeds, news feeds, or anywhere else where you need to lazily fetch and render content for users to consume.

Example

Usage

The InfiniteList API is very similar to that of ListView.builder. A basic implementation requires four parameters:

  • An itemCount that represents the amount of items that should be rendered using the itemBuilder.
  • An itemBuilder that is responsible for returning a widget for every index of the itemCount.
  • A hasReachedMax flag that indicates if any more data is available.
  • An onFetchData callback that's triggered whenever new data should be fetched.

Example

import 'package:flutter/material.dart';
import 'package:very_good_infinite_list/very_good_infinite_list.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  var _items = <String>[];
  var _isLoading = false;

  void _fetchData() async {
    setState(() {
      _isLoading = true;
    });

    await Future.delayed(const Duration(seconds: 1));

    if (!mounted) {
      return;
    }

    setState(() {
      _isLoading = false;
      _items = List.generate(_items.length + 10, (i) => 'Item $i');
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Simple Example'),
      ),
      body: InfiniteList(
        itemCount: _items.length,
        isLoading: _isLoading,
        onFetchData: _fetchData,
        separatorBuilder: (context, index) => const Divider(),
        itemBuilder: (context, index) {
          return ListTile(
            dense: true,
            title: Text(_items[index]),
          );
        },
      ),
    );
  }
}
Customizations
InfiniteList

InfiniteList has multiple optional parameters which allow you to customize the loading and error behavior.

InfiniteList<String>(
  itemCount: 3,
  hasReachedMax: false,
  onFetchData: () => _fetchData(),
  itemBuilder: (context, index) => ListTile(title: Text('$index')),

  // An optional [ScrollController] this [InfiniteList] will attach to.
  // It's used to detect when the list has scrolled to the appropriate position
  // to call [onFetchData].
  //
  // Is optional and mostly used only for testing. If set to `null`, an
  // internal [ScrollController] is used instead.
  scrollController: _scrollController,

  // Indicates if new items are currently being loaded.
  //
  // While set to `true`, the [onFetchData] callback will not be triggered
  // and the [loadingBuilder] will be rendered.
  //
  // Is set to `false` by default.
  isLoading: false,

  // Indicates if an error has occurred.
  //
  // While set to `true`, the [onFetchData] callback will not be triggered
  // and the [errorBuilder] will be rendered.
  //
  // Is set to `false` by default.
  hasError: false,

  // Indicates if the list should be reversed.
  //
  // If set to `true`, the list of items, [loadingBuilder] and [errorBuilder]
  // will be rendered from bottom to top.
  //
  // Is set to `false` by default.
  reverse: false,

  // Indicates if the extent of the ScrollView in the scrollDirection
  // should be determined by the contents being viewed.
  //
  // Is set to `false` by default.
  shrinkWrap: false,

  // The duration with which calls to [onFetchData] will be debounced.
  //
  // Is set to a duration of 100 milliseconds by default.
  debounceDuration: const Duration(milliseconds: 100),

  // The offset, in pixels, that the internal [ScrollView] must be scrolled over
  // to trigger [onFetchData].
  // 
  // Defaults to the same as [RenderAbstractViewport.defaultCacheExtent], which is 250.
  cacheExtent: 250.0,

  // The amount of space by which to inset the list of items.
  //
  // Is optional and can be `null`.
  padding: const EdgeInsets.all(16.0),

  // An optional builder that's shown when the list of items is empty.
  //
  // If `null`, nothing is shown.
  emptyBuilder: (context) => const Center(child: Text('No items.')),
  
  // Flag used to center the empty builder, it is optional and defaults to false
  centerEmpty: true,

  // An optional builder that's shown at the end of the list when [isLoading]
  // is `true`.
  //
  // If `null`, a default builder is used that renders a centered
  // [CircularProgressIndicator].
  loadingBuilder: (context) => const Center(child: CircularProgressIndicator()),

  // Flag used to center the loading builder, it is optional and defaults to false
  centerLoading: true,

  // An optional builder that's shown when [hasError] is not `null`.
  //
  // If `null`, a default builder is used that renders the text `"Error"`.
  errorBuilder: (context) => const Center(child: Text('Error')),

  // Flag used to center the error builder, it is optional and defaults to false
  centerError: true,

  // An optional builder that, when provided, is used to show a widget in
  // between every pair of items.
  //
  // If the [itemBuilder] returns a [ListTile], this is commonly used to render
  // a [Divider] between every tile.
  //
  // Is optional and can be `null`.
  separatorBuilder: (context, index) => const Divider(),

  // An optional [Axis] to be used by the internal [ScrollView] that defines
  // the axis of scroll. 
  //
  // Is set to `Axis.vertical` by default.
  scrollDirection: Axis.vertical,

  // An optional [ScrollPhysics] to be used by the internal [ScrollView].
  //
  // Default to tha same as [ScrollView].
  physics: const AlwaysScrollableScrollPhysics(),
);

Refer to the example to see both basic and complex usage of InfiniteList.

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트