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

패키지 상세v3.0.1

scroll_to_index

Flutter에서 스크롤 가능한 위젯의 특정 자식으로 스크롤하기

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
53.7만
좋아요
821
Pub 점수
140

패키지 설치

flutter pub add scroll_to_index

패키지 개요

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

scroll_to_index 패키지는 Flutter의 ListView 또는 GridView와 같은 모든 스크롤 가능한 위젯 내에서 특정 자식 요소로 정확하게 스크롤할 수 있도록 해줍니다. 인덱스로 프로그래밍 방식으로 스크롤할 수 있는 간단한 API를 제공하여 긴 목록이나 동적 콘텐츠 내 탐색에 이상적입니다. 이 패키지는 Android, iOS, Web, macOS, Windows, Linux 등 주요 플랫폼에서 모두 작동합니다. 사용자 상호작용이나 상태 변경에 따라 특정 항목으로 바로 이동해야 할 때 특히 유용합니다. 구현은 가볍고 기존의 스크롤 가능한 위젯과 원활하게 통합됩니다.

사용 사례

  • 특정 목록 항목으로 이동
  • 긴 스크롤 가능한 목록 내에서 탐색
  • 동적 UI에서의 프로그래머틱 스크롤링
  • 스크롤 가능한 인터페이스에서의 접근성 향상
  • 외부 이벤트와 스크롤 위치 동기화

주요 기능

  • 인덱스 번호로 인덱스로 스크롤
  • 모든 스크롤 가능한 위젯을 지원합니다
  • 크로스 플랫폼 호환성
  • 경량이며 통합이 쉬움
  • 동적 목록과 함께 작동

적합한 대상

  • 리스트 중심 앱을 개발하는 개발자
  • 부드러운 탐색이 필요한 앱
  • 접근성 중심 인터페이스
  • 자주 업데이트되는 동적 콘텐츠

고려 사항

  • 스크롤 컨트롤러를 수동으로 처리해야 합니다
  • 부드러운 애니메이션을 위해 추가적인 로직이 필요할 수 있습니다
  • 최적화 없이 매우 큰 목록에는 적합하지 않습니다

원본 README

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

scroll-to-index

This package provides the scroll to index mechanism for fixed/variable row height for Flutter scrollable widget.

Getting Started

In the pubspec.yaml of your flutter project, add the following dependency:

dependencies:
  ...
  scroll_to_index: any

In your library add the following import:

import 'package:scroll_to_index/scroll_to_index.dart';

For help getting started with Flutter, view the online documentation.

Usage

This is a widget level library, means you can use this mechanism inside any Flutter scrollable widget.

Example for Flutter ListView

ListView(
  scrollDirection: scrollDirection,
  controller: controller,
  children: randomList.map<Widget>((data) {
  	final index = data[0];
  	final height = data[1];
    return AutoScrollTag(
      key: ValueKey(index),
      controller: controller,
      index: index,
      child: Text('index: $index, height: $height'),
      highlightColor: Colors.black.withOpacity(0.1),
    );
  }).toList(),
)

you can wrap any of your row widget which has dynamic row height

AutoScrollTag(
  key: ValueKey(index),
  controller: controller,
  index: index,
  child: child
)

with the AutoScrollController controller.

when you need to trigger scroll to a specified index, you can call

controller.scrollToIndex(index, preferPosition: AutoScrollPosition.begin)

even more, with a fixed row height, you can give it a suggested height for more efficient scrolling. there are more configuration.

final controller = AutoScrollController(
  //add this for advanced viewport boundary. e.g. SafeArea
  viewportBoundaryGetter: () => Rect.fromLTRB(0, 0, 0, MediaQuery.of(context).padding.bottom),

  //choose vertical/horizontal
  axis: scrollDirection,

  //this given value will bring the scroll offset to the nearest position in fixed row height case.
  //for variable row height case, you can still set the average height, it will try to get to the relatively closer offset 
  //and then start searching.
  suggestedRowHeight: 200
);

for full example, please see this Demo.

Who Uses

  • Quire - a simple, collaborative, multi-level task management tool.

카테고리

소스 저장소

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