搜尋套件、儲存庫與 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

所屬分類

原始碼儲存庫

使用此套件的專案