{"id":20839117,"url":"https://github.com/sbdavid/draggable_scrollable_lock_at_top_sheet","last_synced_at":"2026-04-19T20:32:02.778Z","repository":{"id":56828223,"uuid":"252617188","full_name":"SBDavid/draggable_scrollable_lock_at_top_sheet","owner":"SBDavid","description":null,"archived":false,"fork":false,"pushed_at":"2020-04-16T06:37:59.000Z","size":1567,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-18T23:44:46.972Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SBDavid.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-03T02:48:05.000Z","updated_at":"2020-04-16T06:38:02.000Z","dependencies_parsed_at":"2022-08-28T21:10:24.786Z","dependency_job_id":null,"html_url":"https://github.com/SBDavid/draggable_scrollable_lock_at_top_sheet","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SBDavid%2Fdraggable_scrollable_lock_at_top_sheet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SBDavid%2Fdraggable_scrollable_lock_at_top_sheet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SBDavid%2Fdraggable_scrollable_lock_at_top_sheet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SBDavid%2Fdraggable_scrollable_lock_at_top_sheet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SBDavid","download_url":"https://codeload.github.com/SBDavid/draggable_scrollable_lock_at_top_sheet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243196663,"owners_count":20251861,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-18T01:12:23.346Z","updated_at":"2025-12-11T22:37:03.133Z","avatar_url":"https://github.com/SBDavid.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# draggable_scrollable_lock_at_top_sheet\n\n增强版flutter DraggableScrollableSheet，增强点：\n- 滚动区域可以锁定在maxChildSize位置，例如下载加载上一页的时候。\n- 可拖拽扩大，原始的版本是能在ScrollView上执行拖拽，增强后可以在任意位置上拖拽。\n\n## 运行Demo\n\u003cimg src=\"https://raw.githubusercontent.com/SBDavid/draggable_scrollable_lock_at_top_sheet/master/gif/demo.gif\" width=\"270\" height=\"480\" alt=\"图片名称\"\u003e\n\n- 克隆代码到本地: git clone git@github.com:SBDavid/draggable_scrollable_lock_at_top_sheet.git\n- 切换工作路径: cd draggable_scrollable_lock_at_top_sheet/example/\n- 启动模拟器\n- 运行: flutter run\n\n## 使用文档\n### 1. 安装\n\n```yaml\ndependencies:\n  draggable_scrollable_lock_at_top_sheet: ^1.0.0\n```\n\n### 2. 引用插件\n```dart\nimport 'package:draggable_scrollable_lock_at_top_sheet/draggable_scrollable_lock_at_top_sheet.dart';\n```\n\n### 3. 使用组件\n\n在原始的`DraggableScrollableSheet`的基础增加了`shouldLockAtTop`接口，用于判断是否需要锁定在顶部。\n\n```dart\nclass _MyHomePageState extends State\u003cMyHomePage\u003e {\n\n  @override\n  Widget build(BuildContext context) {\n    return Scaffold(\n      appBar: AppBar(\n        elevation: 0,\n        backgroundColor: appBarColor,\n        title: Text(widget.title),\n      ),\n      body: Stack(\n        children: \u003cWidget\u003e[\n          Container(\n            child: RaisedButton(\n              child: Text(\"这个区域可以出发点击事件 当前页码：$currentPageNum\"),\n              onPressed: () {\n                print(\"当前页码：$currentPageNum\");\n              },\n            ),\n          ),\n          LayoutBuilder(\n              builder: (BuildContext context, BoxConstraints constraints) {\n\n                // 计算顶部图片应该保留的空间\n                double minChildSize = (constraints.maxHeight - PIC_HEIGHT) / constraints.maxHeight;\n\n                return NotificationListener(\n                  onNotification: (Notification notification) {\n                    if (notification is DraggableScrollableLockAtTopNotification) {\n                      // 调整appbar颜色\n                      appBarColor = appBarColor.withAlpha(((notification.extent-notification.minExtent)/(notification.maxExtent - notification.minExtent) * 255).ceil());\n                      setState(() {\n\n                      });\n                    }\n                    return false;\n                  },\n                  child: DraggableScrollableSheetLockAtTop(\n                    minChildSize: minChildSize,\n                    maxChildSize: 1,\n                    initialChildSize: minChildSize,\n                    // 判断是否加载到第一页\n                    shouldLockAtTop: () {\n                      return true;\n                    },\n                    builder: (BuildContext context,\n                        ScrollController scrollController) {\n                      return Column(\n                        children: \u003cWidget\u003e[\n                          Container(\n                            color: Colors.red,\n                            height: 80,\n                            width: double.infinity,\n                            child: Text(\"这里可以拖动，滑动到最上会触发锁定，刷新到第一页可以解锁，滑动红色区域也可以解锁\"),\n                          ),\n                          Expanded(\n                            child: Container(\n                              color: Colors.indigo,\n                              child: CustomScrollView(\n                                physics: BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()),\n                                controller: scrollController,\n                                slivers: \u003cWidget\u003e[\n                                  // 下拉加载更多，可以使用别的方式加载更多，这里只做演示。\n                                  CupertinoSliverRefreshControl(\n                                    onRefresh: () async {\n                                      Future.delayed(Duration(seconds: 1), () async {\n                                        if (currentPageNum \u003e 0) {\n                                          currentPageNum--;\n                                          for(int i=0; i\u003cpageSize; i++) {\n                                            items.insert(0, 1);\n                                          }\n                                        }\n                                        setState(() {\n\n                                        });\n                                      });\n                                    },\n                                  ),\n                                  SliverList(\n                                    delegate: SliverChildBuilderDelegate(\n                                            (BuildContext context, int index) {\n                                          return ListTile(title: Text('Item $index'));\n                                        },\n                                        childCount: items.length\n                                    ),\n                                  ),\n                                ],\n                              ),\n                            ),\n                          )\n                        ],\n                      );\n                    },\n                  ),\n                );\n              }\n          )\n        ],\n      )\n    );\n  }\n}\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsbdavid%2Fdraggable_scrollable_lock_at_top_sheet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsbdavid%2Fdraggable_scrollable_lock_at_top_sheet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsbdavid%2Fdraggable_scrollable_lock_at_top_sheet/lists"}