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

extended_sliver 封面
插件详情v2.1.3

extended_sliver

一个强大的 Sliver 扩展库,包含 SliverPinnedPersistentHeader、SliverPinnedToBoxAdapter 和 ExtendedSliverAppbar。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
1.4万
喜欢数
163
Pub 分数
150

安装插件

flutter pub add extended_sliver

插件介绍

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

ExtendedSliver 是一个 Flutter 包,通过额外的可定制组件增强了 Sliver widget 家族的功能。它引入了 SliverPinnedPersistentHeader,用于在滚动时保持固定的标题;SliverPinnedToBoxAdapter,用于将任何 widget 固定在可滚动区域内;以及 ExtendedSliverAppbar,提供高级应用栏功能。专为希望在复杂列表和应用栏中精细控制滚动行为的开发者设计,以最少的样板代码扩展标准 Sliver 的能力。适用于需要跨多个平台实现复杂滚动体验的应用。

适合场景

  • 可自定义的滚动视图中的持久性标题
  • 具有动态行为的高级应用栏设计
  • 在可滚动列表中将小部件固定在特定位置
  • 创建复杂的滚动布局
  • 使用分层滚动效果构建响应式 UI
  • 通过优化滑块使用来提升列表性能

主要特点

  • SliverPinnedPersistentHeader 用于粘性标题
  • SliverPinnedToBoxAdapter 用于固定任意小部件
  • 带有增强自定义功能的 ExtendedSliverAppbar
  • 支持所有主要平台
  • 最小设置,直观的 API
  • 大型列表的优化性能

适合对象

  • 开发复杂可滚动界面的开发者
  • UI设计师需要对滚动行为进行精确控制
  • 具有动态或分层内容布局的应用程序
  • 跨平台 Flutter 应用
  • 致力于减少自定义滚动逻辑的团队
  • 需要可重用、可维护的滑块组件的项目

使用建议

  • 需要熟悉 Sliver 小部件
  • 可能会增加简单滚动视图的复杂性
  • 最适合高级用例
  • 除了基本示例外,文档有限
  • 如果过度使用,可能会对性能产生影响
  • 不适合初学者学习Flutter基础

原始 README

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

extended_sliver

pub package GitHub stars GitHub forks GitHub license GitHub issues FlutterCandies QQ 群

Language: English | 中文简体

Description

A powerful extension library of Sliver, which include SliverToNestedScrollBoxAdapter, SliverPinnedPersistentHeader, SliverPinnedToBoxAdapter and ExtendedSliverAppbar.

Usage

Add packages to dependencies

Add the package to pubspec.yaml under dependencies.

dependencies:
  extended_sliver: latest-version

Download with flutter packages get

SliverPinnedPersistentHeader

It's the same as SliverPersistentHeader(pinned: true), but you don't have to force values of minExtent and maxExtent.

It provides minExtentProtoType and maxExtentProtoType to calculate minExtent and maxExtent automatically.

It's useful that you don't know the final extent before the widgets are laid out.

    SliverPinnedPersistentHeader(
      delegate: MySliverPinnedPersistentHeaderDelegate(
        minExtentProtoType: Container(
          height: 120.0,
          color: Colors.red.withOpacity(0.5),
          child: FlatButton(
            child: const Text('minProtoType'),
            onPressed: () {
              print('minProtoType');
            },
          ),
          alignment: Alignment.topCenter,
        ),
        maxExtentProtoType: Container(
          height: 200.0,
          color: Colors.blue,
          child: FlatButton(
            child: const Text('maxProtoType'),
            onPressed: () {
              print('maxProtoType');
            },
          ),
          alignment: Alignment.bottomCenter,
        ),
      ),
    )

SliverPinnedToBoxAdapter

You can create a pinned Sliver easily with it.

It's useful that you don't know the final extent before the child are laid out.

    SliverPinnedToBoxAdapter(
      child: Container(
        padding: const EdgeInsets.all(20),
        color: Colors.blue.withOpacity(0.5),
        child: Column(
          children: <Widget>[
            const Text(
                '[love]Extended text help you to build rich text quickly. any special text you will have with extended text. '
                '\n\nIt\'s my pleasure to invite you to join \$FlutterCandies\$ if you want to improve flutter .[love]'
                '\n\nif you meet any problem, please let me konw @zmtzawqlp .[sun_glasses]'),
            FlatButton(
              child: const Text('I\'m button. click me!'),
              onPressed: () {
                debugPrint('click');
              },
            ),
          ],
        ),
      ),
    )

ExtendedSliverAppbar

You can create SliverAppbar with out force the expandedHeight.

return CustomScrollView(
  slivers: <Widget>[
    ExtendedSliverAppbar(
      title: const Text(
        'ExtendedSliverAppbar',
        style: TextStyle(color: Colors.white),
      ),
      leading: const BackButton(
        onPressed: null,
        color: Colors.white,
      ),
      background: Image.asset(
        'assets/cypridina.jpeg',
        fit: BoxFit.cover,
      ),
      actions: Padding(
        padding: const EdgeInsets.all(10.0),
        child: Icon(
          Icons.more_horiz,
          color: Colors.white,
        ),
      ),
    ),
  ],
);

SliverToNestedScrollBoxAdapter

You can create nested scrollable widget(like Webview) in CustomScrollView/NestedScrollView.

return CustomScrollView(
  slivers: <Widget>[
      SliverToBoxAdapter(
        child: Container(
          height: 100,
          color: Colors.red,
          child: const Center(
            child: Text(
              'Header',
              style: TextStyle(color: Colors.white),
            ),
          ),
        ),
      ),
    ValueListenableBuilder<double>(
      valueListenable: nestedWebviewController.scrollHeightNotifier,
      builder: (
        BuildContext context,
        double scrollHeight,
        Widget? child,
      ) {
        return SliverToNestedScrollBoxAdapter(
          childExtent: scrollHeight,
          onScrollOffsetChanged: (double scrollOffset) {
            double y = scrollOffset;
            if (Platform.isAndroid) {
              // https://github.com/flutter/flutter/issues/75841
              y *= window.devicePixelRatio;
      
            nestedWebviewController.webviewController
                ?.scrollTo(0, y.ceil());
          },
          child: child,
        );
      },
      child: WebView(
        initialUrl: nestedWebviewController.initialUrl,
        onPageStarted: nestedWebviewController.onPageStarted,
        onPageFinished: nestedWebviewController.onPageFinished,
        onWebResourceError:
            nestedWebviewController.onWebResourceError,
        onWebViewCreated: nestedWebviewController.onWebViewCreated,
        onProgress: nestedWebviewController.onProgress,
        javascriptChannels: <JavascriptChannel>{
          nestedWebviewController
              .scrollHeightNotifierJavascriptChannel
        },
        javascriptMode: JavascriptMode.unrestricted,
      ),
    ),
    SliverToBoxAdapter(
        child: Container(
          height: 300,
          color: Colors.green,
          child: const Center(
            child: Text(
              'Footer',
              style: TextStyle(color: Colors.white),
            ),
          ),
        ),
    ),
  ],
);

Complex Demo

Complex Demo

image

所属分类

源码仓库

使用此插件的项目