搜尋套件、儲存庫與 APP 分類

套件詳情v3.1.0

nested_scroll_view_plus

一個增強版的 NestedScrollView,為嵌套與父級滾動視圖都提供越界滾動支援,確保流暢的滾動體驗。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
7890
喜歡數
49
Pub 分數
150

安裝套件

flutter pub add nested_scroll_view_plus

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

Flutter 的 NestedScrollView 增強版本,為嵌套與父層滾動檢視提供過滾動支援,確保跨平台的流暢且一致的滾動體驗。它透過允許兩層皆具備自然過滾動效果,改善預設行為,非常適合應用程式列搭配下方可滾動內容等複雜滾動佈局。此套件持續維護,並相容於 Android、iOS、Web、macOS、Windows 與 Linux。

適用情境

  • 複雜的應用欄佈局
  • 嵌套可滾動內容的過度滾動
  • 帶有視差效果的滾動
  • 具有分層滾動的響應式 UI
  • 混合可捲動介面

主要特色

  • 對嵌套和父級滾動視圖的越界支援
  • 無縫滾動體驗
  • 跨平台相容性
  • 改進的滾動物理效果
  • 對自定義滾動行為的支援
  • 積極維護與更新

適合對象

  • 開發進階可捲動 UI 的開發者
  • 需要層疊滾動並帶有視覺反饋的應用程式
  • 需要一致回彈行為的項目
  • 針對多個平台的團隊
  • 實現動態滾動效果的UI設計師

使用建議

  • 可能會增加簡單滾動佈局的複雜性
  • 需要小心處理滾動控制器
  • 深度嵌套滾動可能帶來的效能影響
  • 基本可滾動組件不需要
  • 最適合高階使用案例,而非標準的 NestedScrollView

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

NestedScrollViewPlus

pub package monthly downloads Stars

An enhanced NestedScrollView offering overscroll support for both the nested and parent scroll views, ensuring a seamless scrolling experience.

🔥 Preview

Try it online: https://flutter-nested-scroll-view-plus.vercel.app

⚡️ Get Started

Install NestedScrollViewPlus by running the following command:

flutter pub add nested_scroll_view_plus

Here’s a basic example:

import 'package:nested_scroll_view_plus/nested_scroll_view_plus.dart';

// Step 1: Replace `NestedScrollView` with `NestedScrollViewPlus`
NestedScrollViewPlus(
  headerSliverBuilder: (context, innerScrolled) => <Widget>[
    // ... insert your header sliver widgets here
  ],
  body: CustomScrollView(
    // Step 2: [🚨IMPORTANT] Set the physics of `CustomScrollView` to `AlwaysScrollableScrollPhysics`
    physics: const BouncingScrollPhysics(
      parent: AlwaysScrollableScrollPhysics(),
    ),
    slivers: <Widget>[
      // ... insert your body sliver widgets here
    ],
  ),
);

For additional examples, please visit the scroll_master repository. It includes features such as pull-to-refresh for NestedScrollView, combined scrolling for scrollview and tabview, and more.

🚗 Examples

1. Loading Indicator
NestedScrollViewPlus(
  overscrollBehavior: OverscrollBehavior.outer,
  headerSliverBuilder: (context, innerScrolled) => <Widget>[
    // Place the refresh indicator at the top of the header slivers
    CupertinoSliverRefreshControl(
      onRefresh: () async {
        // fetching data
      },
    ),
    // Add your custom AppBar or other header sliver widgets here.
  ],
  // ...
)
2. Accessing the Inner or Outer Scroll Controller

To access the inner or outer scroll controller of a NestedScrollViewPlus, you can use a GlobalKey<NestedScrollViewStatePlus> to get its state.

👉 Example
class _ExampleState extends State<Example> {
  // 1. Create a GlobalKey
  final GlobalKey<NestedScrollViewStatePlus> myKey = GlobalKey();

  @override
  Widget build(BuildContext context) {
    return NestedScrollViewPlus(
      // 2. Set the key to NestedScrollViewStatePlus
      key: myKey,
      // ...,
    );
  }

  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
      // 3. Access the inner or outer scroll controller using GlobalKey<NestedScrollViewStatePlus>
      myKey.currentState!.innerController.addListener(_handleInnerScroll);
      myKey.currentState!.outerController.addListener(_handleOuterScroll);
    });
  }

  void _handleInnerScroll() {
    final innerController = myKey.currentState!.innerController;
    if (innerController.positions.length == 1) {
      print('Scrolling inner nested scrollview: ${innerController.offset}');
    }
  }

  void _handleOuterScroll() {
    final outerController = myKey.currentState!.outerController;
    if (outerController.positions.length == 1) {
      print('Scrolling outer nested scrollview: ${outerController.offset}');
    }
  }
}
3. Preserve Scroll Positions of Inner CustomScrollViews

To preserve the scroll positions of inner CustomScrollViews, you can add a PageStorageKey to the CustomScrollView widget. Here's an example:

CustomScrollView(
  key: PageStorageKey<String>('your-unique-key'),
  slivers: <Widget>[
    // ...,
  ],
),

By assigning a unique key to the CustomScrollView, Flutter's PageStorage mechanism will store and restore the scroll position of the inner CustomScrollViews, allowing you to maintain the scroll positions even when the widget tree is rebuilt.

⭕️ For Older Flutter Versions

If you are using an older version of Flutter, please follow these steps to install the appropriate branch from the old git repository.

dependencies:
  custom_nested_scroll_view:
    git:
      url: https://github.com/idootop/custom_nested_scroll_view.git
      # Choose the branch based on your local Flutter version
      ref: flutter-3.7

The different branches support the following Flutter versions:

Git branch Supported flutter versions
flutter-3.7 >=3.7.0-13.0.pre
flutter-3.4 >=3.4.0-27.0.pre <3.7.0-13.0.pre
flutter-3.4-pre >=3.4.0-17.0.pre <3.4.0-27.0.pre
flutter-3.0 >=2.12.0-4.0.pre <3.4.0-17.0.pre
flutter-2.x <2.12.0-4.0.pre

For more details, please visit the old documentation for CustomNestedScrollView.

❤️ Acknowledgements

⚖️ License

MIT License © 2024-PRESENT Del Wang

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。