搜索插件、代码仓与 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

所属分类

源码仓库

使用此插件的项目

暂无相关数据。