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

flutter_scroll_to_top 표지
패키지 상세v2.3.0

flutter_scroll_to_top

사용자가 스크롤할 때 위로 이동 프롬프트를 표시할 수 있도록, 스크롤 가능한 위젯을 감싸는 간단한 래퍼를 제공하는 패키지입니다.

30일 다운로드
322
좋아요
104
Pub 점수
70

패키지 설치

flutter pub add flutter_scroll_to_top

패키지 개요

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

사용자가 아래로 스크롤할 때 자동으로 '맨 위로 스크롤' 표시기를 표시하도록 스크롤 가능한 위젯을 래핑하는 가벼운 플러터 패키지입니다. 긴 목록이나 스크롤 뷰의 맨 위로 돌아가는 직관적인 방법을 제공하여 사용자 경험을 향상시킵니다. 이 패키지는 ListView, CustomScrollView 또는 SingleChildScrollView와 같은 모든 스크롤 가능한 콘텐츠와 원활하게 작동하며, 버튼의 외관과 동작을 사용자 정의할 수 있습니다.

사용 사례

  • 긴 목록에 위로 스크롤 버튼 추가하기
  • 스크롤 가능한 대시보드에서 UX 개선
  • 콘텐츠가 많은 앱에서 접근성 향상
  • 스크롤 중 시각적 피드백 제공
  • 중첩 스크롤 뷰 내 탐색 간소화

주요 기능

  • 스크롤 위치에 기반한 자동 표시
  • 사용자 정의 가능한 플로팅 액션 버튼
  • 라퍼 위젯을 사용한 최소 설정
  • 모든 스크롤 가능한 위젯과 호환됩니다
  • 다크 모드 및 테마 통합을 지원합니다

적합한 대상

  • 긴 스크롤 가능한 콘텐츠를 가진 앱
  • UX를 우선시하는 사용자 인터페이스 디자이너
  • 빠른 스크롤 상단 이동 구현을 찾는 개발자
  • 최소 종속성 요구 프로젝트
  • 콘텐츠가 풍부한 화면을 갖춘 모바일 앱

고려 사항

  • 추가 구성 없이 복잡한 중첩 스크롤 뷰와 함께 작동하지 않을 수 있습니다
  • 기본값을 사용하지 않는 경우 수동으로 스크롤 컨트롤러를 처리해야 합니다
  • 기본 스타일 외에 사용자 지정 옵션이 제한적입니다
  • 스크롤이 불가능한 위젯에는 적합하지 않습니다
  • 플랫폼별 스크롤 동작에 의존합니다

원본 README

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

flutter_scroll_to_top

Pub

A wrapper to show a scroll to top prompt to the user on ScrollView widgets.

Installing

Add the following dependency to your pubspec.yaml file:

dependencies:
  flutter_scroll_to_top: ^2.2.4

Import the package

import 'package:flutter_scroll_to_top/flutter_scroll_to_top.dart';

ScrollWrapper

Just wrap the scrollable widget you want to show the scroll to top prompt over with a ScrollWrapper.

ScrollWrapper(
    builder: (context, properties) => ListView.builder(
        itemBuilder: (context, index) => Padding(
            padding: const EdgeInsets.all(8.0),
            child: ListTile(
                title: Text('Tile $index'),
                tileColor: Colors.grey.shade200,
            ),
        ),
    ),
)

ScrollView Properties

If the child ScrollView has different properties for scrollController, scrollDirection, primary or reverse parameters than the default values, you need to pass them to the ScrollWrapper widget as it requires the same parameters. It provides a ScrollViewProperties object in the builder callback that you can use to access the properties in the ScrollView widget.

ScrollWrapper(
    primary: true,
    scrollDirection: Axis.horizontal,
    reverse: true,
    builder: (context, properties) => ListView.builder(
        controller: properties.scrollController,
        scrollDirection: properties.scrollDirection,
        reverse: properties.reverse,
        primary: properties.primary,
        itemBuilder: (context, index) => Padding(
            padding: const EdgeInsets.all(8.0),
            child: ListTile(
                title: Text('Tile $index'),
                tileColor: Colors.grey.shade200,
            ),
        ),
    ),
)

Customisation

You can pass the following parameters to customise the prompt accordingly

  • enabledAtOffset - At what scroll offset to enable the prompt on.
  • alwaysVisibleAtOffset - If the prompt is to be always visible at the provided offset. Setting this to false only shows the prompt when the user starts scrolling upwards. Default value is false.
  • scrollOffsetUntilVisible - Offset should the user scroll in the opposite direction before the prompt becomes visible.
  • scrollOffsetUntilHide - Offset should the user scroll before the prompt hides itself, if visible.
  • promptAlignment - Where on the widget to align the prompt.
  • promptDuration - Duration it takes for the prompt to come into view/vanish.
  • promptAnimationCurve - Animation Curve that the prompt will follow when coming into view.
  • promptAnimationType - PromptAnimation that the prompt follows when animating. Has three options, fade, scale and size.
  • scrollToTopDuration - Duration it takes for the page to scroll to the top on prompt button press.
  • scrollToTopCurve - Animation Curve for scrolling to the top.
  • promptTheme - You can pass PromptButtonTheme to modify the prompt button further. It has the following parameters:
    • padding - Padding around the prompt button.
    • iconPadding - Padding around the icon inside the button.
    • icon - The icon inside the button.
    • color - Color of the prompt button.
    • elevation - Elevation of the button.
ScrollWrapper(
    promptAlignment: Alignment.topCenter,
    promptAnimationCurve: Curves.elasticInOut,
    promptDuration: const Duration(milliseconds: 400),
    enabledAtOffset: 300,
    scrollOffsetUntilVisible: 500,
    promptTheme: const PromptButtonTheme(
    icon: Icon(Icons.arrow_circle_up, color: Colors.amber),
    color: Colors.deepPurpleAccent,
    iconPadding: EdgeInsets.all(16),
    padding: EdgeInsets.all(32)),
    builder: (context, properties) => ListView.builder(
        controller: properties.scrollController,
        scrollDirection: properties.scrollDirection,
        reverse: properties.reverse,
        primary: properties.primary,
            itemBuilder: (context, index) => Padding(
            padding: const EdgeInsets.all(8.0),
            child: ListTile(
                title: Text('Tile $index'),
                tileColor: Colors.grey.shade200,
            ),
        ),
    ),
)

Custom Prompt Widget

You can replace the default prompt widget with a widget of your choosing by passing it off in the promptReplacementBuilder parameter.

ScrollWrapper(
    promptReplacementBuilder: (context, function) => MaterialButton(
        onPressed: () => function(),
        child: const Text('Scroll to top'),
    ),
    builder: (context, properties) => ListView.builder(
        controller: properties.scrollController,
        scrollDirection: properties.scrollDirection,
        reverse: properties.reverse,
        primary: properties.primary,
        itemBuilder: (context, index) => Padding(
            padding: const EdgeInsets.all(8.0),
            child: ListTile(
                title: Text('Tile $index'),
                tileColor: Colors.grey.shade200,
            ),
        ),
    ),
)


The prompt shows up inconsistently if I have multipe scrollviews listening to the same scroll controller, how do I fix it?

This is a limitation of the way Flutter handles this scenario. If you are receiving this error (likely due to multiple scrollables under a NestedScrollView), this library bundles a modified version of the scrollviews which would fix this issue.

To use them, add the following import:

import 'package:flutter_scroll_to_top/scroll_view.dart' as scrollview;

Then replace your scrollview in the following way:

Before

ScrollWrapper(
    builder: (context, properties) => ListView.builder(
        itemBuilder: (context, index) => Padding(
            padding: const EdgeInsets.all(8.0),
            child: ListTile(
                title: Text('Tile $index'),
                tileColor: Colors.grey.shade200,
            ),
        ),
    ),
)

After

ScrollWrapper(
    builder: (context, properties) => scrollview.ListView.builder(
        properties: properties,
        itemBuilder: (context, index) => Padding(
            padding: const EdgeInsets.all(8.0),
            child: ListTile(
                title: Text('Tile $index'),
                tileColor: Colors.grey.shade200,
            ),
        ),
    ),
)

카테고리

소스 저장소

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