搜索插件、代码仓与 APP 分类

sliver_snap 封面
插件详情v2.1.1

sliver_snap

允许您使用功能强大的吸顶滑块,包含展开和折叠的标题栏。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
7730
喜欢数
104
Pub 分数
160

安装插件

flutter pub add sliver_snap

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

SliverSnap 是一个 Flutter 包,可帮助开发者创建动态的、带有吸附效果的 Sliver,并支持可展开和可折叠的标题栏。它通过实现展开和折叠状态之间的平滑过渡来增强滚动交互,非常适合创建沉浸式应用界面。该包可无缝集成到 CustomScrollView 中,并支持所有主要平台,包括 Android、iOS、Web、macOS、Windows 和 Linux。它特别适用于实现现代 UI 模式,如视差标题和交互式导航栏。

适合场景

  • 创建交互式应用标题
  • 实现视差滚动效果
  • 构建响应式导航栏
  • 设计沉浸式用户体验
  • 开发滚动驱动的动画
  • 增强内容发现界面

主要特点

  • 平滑的吸附行为
  • 支持展开和折叠状态
  • 与 CustomScrollView 的无缝集成
  • 跨平台兼容性
  • 可自定义的快照点
  • 实时滚动反馈

适合对象

  • 开发现代 Flutter 应用的开发者
  • UI 设计师实现动态标题
  • 需要基于滚动的交互的应用程序
  • 具有复杂滚动布局的项目
  • 专注于打造精致用户体验的团队

使用建议

  • 需要了解 CustomScrollView
  • 可能需要对大型列表进行性能调优
  • 除了基本用法外,文档有限
  • 不适合简单的静态标题
  • 最适合高级UI组件
  • 嵌套滚动场景中的潜在复杂性

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Sliver-Snap Banner Image

Sliver Snap

Platform Pub Package License: MIT

🚀 Sliver Snap is a Flutter package that simplifies the process of adding collapsible and expandable app bars to your app. It offers smooth transitions that respond seamlessly to user scrolling and snaps to the appropriate mode when the user stops scrolling midway. 💻 It's highly customizable and provides a user-friendly experience.
Say goodbye to manual implementation and make your Flutter app more interactive and intuitive with Sliver Snap. 🤯

Table of contents

Preview

basic Performance
Android Basic PPerformance image

Installing

1. Depend on it

Add this to your package's pubspec.yaml file:

dependencies:
  sliver_snap: ^2.0.0

or you can add the latest version from the command line:

flutter pub add sliver_snap
2. Install it

You can install packages from the command line with Flutter:

$ flutter pub get
3. Import it

Now in your Dart code, you can use:

import 'package:sliver_snap/sliver_snap.dart';

Basic Usage

  SliverSnap(
    onCollapseStateChanged: (isCollapsed, scrollingOffset, maxExtent) {},
    collapsedBackgroundColor: Colors.black,
    expandedBackgroundColor: Colors.transparent,
    backdropWidget: Image.network(
      "https://picsum.photos/800/1200",
      fit: BoxFit.cover,
    ),
    bottom: const PreferredSize(
      preferredSize: Size.fromHeight(50),
      child: Icon(
        Icons.directions_boat,
        color: Colors.blue,
        size: 45,
      ),
    ),
    expandedContentHeight: 400,
    expandedContent: const Center(
      child: Icon(
        Icons.ac_unit_sharp,
        color: Colors.amber,
        size: 70,
      ),
    ),
    collapsedContent:
    const Icon(Icons.car_crash, color: Colors.green, size: 45),
    body: const Material(
      elevation: 7,
      child: Placeholder(),
    ),
  );
Properties
Property Type Default Value Description
expandedContent Widget N/A The content that is shown when expanded.
It is a required property.
collapsedContent Widget N/A The appbar Which is shown when collapsed.
It is a required property.
body Widget N/A The content shown below the appbar.
It is a required property.
pinned boolean true Whether the appbar will be fixed at the top of the scroll view.
For more information check the documentation For more information check the flutter docs.
collapsedBarHeight double 60.0 The height of the collapsedContent.
animationDuration Duration 300 milliseconds The duration of the scroll animation which happens when automatically snapping to the collapsed or the expanded widgets.
animationCurve Curve Curves.easeInOut The Curve of the scroll animation which happens when automatically snapping to the collapsed or the expanded widgets.
snap boolean false Whether the app bar behave in a smooth or a rigid way as the it is scrolling.
For more information check the documentation flutter docs.
floating boolean false Whether the app bar should become visible as soon as the user scrolls towards the app bar.
For more information check the flutter docs.
stretch boolean false Whether the app bar should stretch to fill the over-scroll area.
For more information check the flutter docs.
expandedContentHeight double? N/A The height of the expandedContent.
bottom PreferredSizeWidget? N/A The widget that appears across the bottom of the appbar. For example a TabBar.
This widget has to implement a PreferredSizeWidget.
automaticallyImplyLeading bool? false Provides Control of the AppBar's leading widget. When set to true, the framework will automatically add a leading widget
When set to false , no leading widget will be added automatically.
For more information check the flutter docs.
leading Widget? N/A The leading widget at the start both the expandedContent and the collapsedContent, typically an Icon or an IconButton. It can also be a BackButton.
actions List? N/A A list of action widgets to display in a row after the collapsedContent widget.
backdropWidget Widget? N/A The content that is shown below the appbar. In most cases it's just the page content.
expandedBackgroundColor Color? N/A The background Color of the expandedContent widget.
collapsedBackgroundColor Color? N/A The background Color of the collapsedContent widget.
scrollController ScrollController? N/A Can be used to pass your own scrollController to customize the appbar even more.
scrollBehavior ScrollBehaviour? N/A How the scrollable widgets behave, either Material or Cupertino Scrolling behaviors.
onCollapseStateChanged CollapsingStateCallback? N/A This is a callback function that is triggered when the bar is either collapsed or expanded. It can be used to customize the animation and behavior of the widget to better suit your needs.
elevation double 0.0 The elevation of the app bar
forceElevated bool false Whether to show the shadow appropriate for the elevation even if the content is not scrolled under the app bar. Defaults to false, meaning that the elevation is only applied when the app bar is being displayed over content that is scrolled under it.

Extra Components

The below are supplementary widgets that can help you build the appbar faster.

1. Collapsed AppBar Content widget

This can be used to create a custom collapsedContent widget. It has the following properties:

  1. leading: This is the leading widget specifically for the collapsedContent Appbar. Don't add the leading widget to the ExpandedContent widget or the SliverSnap widget, as they might overlap.
  2. title: The middle widget between the leading and the trailing of the collapsedContent Appbar.,
  3. trailing: The widget that is displayed at the rightmost part of the collapsedContent.
      CollapsedAppBarContent(
        leading: const Text('Leading Widget'),
        title: const Text('title'),
        trailing: SizedBox(
          height: 40,
          child: Image.network(
            'https://picsum.photos/800/1200',
            fit: BoxFit.cover,
          ),
        ),
      ),
2. Expanded Content widget

This can be used to create a custom expanded widget. It has the following properties:

  1. leading: This is the leading widget specifically for the expandedContent Appbar. Don't add the leading widget to the CollapsedAppBarContent widget or the SliverSnap widget, as they might overlap.
    ExpandedContent(
      leading: const Text('Leading Widget'),
      child: const Text('Expanded Content'),
    );

Additional information

Feel free to check the example for more usage info.

Bugs or Requests

If you encounter any problems feel free to open an issue. If you feel the library is missing a feature, please raise a ticket. Pull request are also welcome.

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目

暂无相关数据。