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

scroll_to_id 표지
패키지 상세v1.5.1

scroll_to_id

scroll_to_id는 ScrollView 내 각 위젯에 정의된 ID를 선택함으로써 화면을 자동 스크롤할 수 있도록 해주는 Flutter 라이브러리입니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
177
좋아요
61
Pub 점수
150

패키지 설치

flutter pub add scroll_to_id

패키지 개요

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

scroll_to_id는 특정 위젯의 고유 ID를 참조하여 스크롤 가능한 뷰 내에서 자동으로 스크롤할 수 있도록 해주는 Flutter 패키지입니다. 긴 목록이나 스크롤 가능한 레이아웃에서의 탐색을 단순화하며, 개발자가 할당된 ID 기반으로 프로그래밍 방식으로 요소로 스크롤할 수 있게 합니다. 동적 콘텐츠, 앵커 링크, 또는 폼 검증 시 오류 위치로 스크롤하는 기능에 이상적입니다. 이 패키지는 모든 주요 플랫폼을 지원하며 기존 스크롤 뷰에 원활하게 통합됩니다.

사용 사례

  • 특정 목록 항목으로 이동하기
  • 오류가 있는 폼 필드로 스크롤하기
  • 긴 페이지에서 앵커 링크 구현
  • 부드러운 섹션 전환 만들기
  • 이동 후 자동 스크롤
  • 키보드 단축키를 통한 접근성 향상

주요 기능

  • ID로 위젯으로 스크롤
  • 모든 플러터 플랫폼을 지원합니다
  • 필요한 설정 최소화
  • 모든 스크롤 가능한 위젯과 호환됩니다
  • 전역 키가 필요하지 않습니다
  • 대규모 목록에서의 효율적인 성능

적합한 대상

  • 장편 콘텐츠 앱을 개발하는 개발자
  • 동적 목록을 사용하는 팀
  • 앵커 탐색이 필요한 앱
  • 접근성 중심 애플리케이션
  • 폼 중심 인터페이스

고려 사항

  • 스크롤 뷰 내에서 ID는 고유해야 합니다
  • 매우 큰 목록에서는 성능이 달라질 수 있습니다
  • 올바른 위젯 구조가 필요합니다
  • 스크롤이 불가능한 컨테이너에 적합하지 않습니다
  • 스크롤 가능한 위젯의 직접 자식에 한정

원본 README

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

Scroll to id

scroll_to_id is a Flutter library for Scroll to id in ScrollView

Image Image

Installing

You should add the following to your pubspec.yaml file:

dependencies:
  scroll_to_id: ^1.5.1

Getting Started

To start, import the dependency in your code:

import 'package:scroll_to_id/scroll_to_id.dart';

Next, to define ScrollController:

final scrollController = ScrollController();

Next, to create instance with ScrollController:

ScrollToId scrollToId = ScrollToId(scrollController: scrollController);

Next, to set InteractiveScrollViewer and ScrollContent:

InteractiveScrollViewer(
  scrollToId: scrollToId,
  children: <ScrollContent>[
    ScrollContent(
      id: 'a',
      child: Container(
        color: Colors.red,
        width: 300,
        height: 200,
      )
    ),
    ScrollContent(
      id: 'b',
      child: Container(
        color: Colors.green,
        width: 300,
        height: 200,
      )
    ),
  ],
)

id property is destination of scroll. Do not use the same id.

Next, to scroll to id:

/// animate
scrollToId.animateTo(
  'b',
  duration: Duration(milliseconds: 500),
  curve: Curves.ease
);

/// jump
scrollToId.jumpTo('b');

Examples

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

void main() {
  runApp(MyApp());
}

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

class _MyAppState extends State<MyApp> {
  ScrollToId scrollToId;
  final ScrollController scrollController = ScrollController();

  List<Color> _colorList = [
    Colors.green,
    Colors.red,
    Colors.yellow,
    Colors.blue
  ];

  void _scrollListener() {
    print(scrollToId.idPosition());
  }

  @override
  void initState() {
    super.initState();

    /// Create ScrollToId instance
    scrollToId = ScrollToId(scrollController: scrollController);

    scrollController.addListener(_scrollListener);
  }

  /// Generate 10 Container
  /// Case [Axis.horizontal] set buildStackHorizontal() to body
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Scroll to id',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Scroll to id'),
        ),
        body: buildStackVertical(),
      ),
    );
  }

  /// [Axis.vertical]
  /// https://raw.githubusercontent.com/wiki/yusukeinouehatchout/scroll_to_id/gif/scroll_to_id_vertical.gif
  Widget buildStackVertical() {
    return Stack(
      alignment: Alignment.topRight,
      children: [
        InteractiveScrollViewer(
          scrollToId: scrollToId,
          children: List.generate(10, (index) {
            return ScrollContent(
              id: '$index',
              child: Container(
                alignment: Alignment.center,
                width: double.infinity,
                height: 200,
                child: Text(
                  '$index',
                  style: TextStyle(color: Colors.white, fontSize: 50),
                ),
                color: _colorList[index % _colorList.length],
              ),
            );
          }),
        ),
        Container(
          decoration: BoxDecoration(
            border: Border.all(color: Colors.white, width: 3),
          ),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: List.generate(10, (index) {
              return GestureDetector(
                child: Container(
                  width: 100,
                  alignment: Alignment.center,
                  height: 50,
                  child: Text(
                    '$index',
                    style: TextStyle(color: Colors.white),
                  ),
                  color: _colorList[index % _colorList.length],
                ),
                onTap: () {
                  /// scroll with animation
                  scrollToId.animateTo('$index',
                      duration: Duration(milliseconds: 500),
                      curve: Curves.ease);

                  /// scroll with jump
                  // scrollToId.jumpTo('$index');
                },
              );
            }),
          ),
        )
      ],
    );
  }

  /// [Axis.horizontal]
  /// https://raw.githubusercontent.com/wiki/yusukeinouehatchout/scroll_to_id/gif/scroll_to_id_horizontal.gif
  Widget buildStackHorizontal() {
    return Column(
      children: [
        Container(
          width: double.infinity,
          decoration: BoxDecoration(
            border: Border.all(color: Colors.white, width: 3),
          ),
          child: Row(
            mainAxisSize: MainAxisSize.min,
            children: List.generate(10, (index) {
              return Expanded(
                child: GestureDetector(
                  child: Container(
                    alignment: Alignment.center,
                    height: 80,
                    child: Text(
                      '$index',
                      style: TextStyle(color: Colors.white),
                    ),
                    color: _colorList[index % _colorList.length],
                  ),
                  onTap: () {
                    /// scroll with animation
                    scrollToId.animateTo('$index',
                        duration: Duration(milliseconds: 500),
                        curve: Curves.ease);

                    /// scroll with jump
                    // scrollToId.jumpTo('$index');
                  },
                ),
              );
            }),
          ),
        ),
        Expanded(
          child: InteractiveScrollViewer(
            scrollToId: scrollToId,
            scrollDirection: Axis.horizontal,
            children: List.generate(10, (index) {
              return ScrollContent(
                id: '$index',
                child: Container(
                  alignment: Alignment.center,
                  width: 200,
                  child: Text(
                    '$index',
                    style: TextStyle(color: Colors.white, fontSize: 50),
                  ),
                  color: _colorList[index % _colorList.length],
                ),
              );
            }),
          ),
        ),
      ],
    );
  }
}

카테고리

소스 저장소

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

아직 데이터가 없습니다.