### Basic ListView Setup Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/2、Scrolling-to-the-specified-index-location Demonstrates the basic setup for a ListView with ScrollController and ListObserverController. ```dart ScrollController scrollController = ScrollController(); ListView _buildListView() { return ListView.separated( controller: scrollController, ... ); } ``` ```dart ListObserverController observerController = ListObserverController(controller: scrollController); ListViewObserver( controller: observerController, child: _buildListView(), ... ) ``` -------------------------------- ### SliverAppBar Configuration Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/2、Scrolling-to-the-specified-index-location Example configuration for a SliverAppBar, which is often used in scenarios requiring dynamic scroll offsets. ```dart SliverAppBar( key: appBarKey, pinned: true, expandedHeight: 200, flexibleSpace: FlexibleSpaceBar( title: const Text('AppBar'), background: Container(color: Colors.orange), ), ); ``` -------------------------------- ### CustomScrollView Setup with SliverViewObserver Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/2、Scrolling-to-the-specified-index-location Shows how to integrate SliverViewObserver with CustomScrollView for observing slivers like SliverList and SliverGrid. ```dart SliverViewObserver( controller: observerController, child: CustomScrollView( controller: scrollController, slivers: [ _buildSliverListView1(), _buildSliverListView2(), ], ), sliverListContexts: () { return [ if (_sliverViewCtx1 != null) _sliverViewCtx1!, if (_sliverViewCtx2 != null) _sliverViewCtx2!, ]; }, ... ) ``` -------------------------------- ### Set Initial Index (Simple) Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/2、滚动到指定下标位置 Sets the initial scroll index using the `initialIndex` property for a ListObserverController. This is the simplest way to specify the starting position. ```dart observerController = ListObserverController(controller: scrollController) ..initialIndex = 10; ``` -------------------------------- ### Listening to Scroll State Notifications in Flutter Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/2、Scrolling-to-the-specified-index-location Use NotificationListener with ObserverScrollNotification to detect different scrolling states like start, interruption, decision, and end. This is useful for managing UI updates or performing actions based on scroll events. ```dart NotificationListener( child: widget, onNotification: (notification) { if (notification is ObserverScrollStartNotification) { } else if (notification is ObserverScrollInterruptionNotification) { } else if (notification is ObserverScrollDecisionNotification) { } else if (notification is ObserverScrollEndNotification) { } return true; }, ); ``` -------------------------------- ### Initialize ListObserverController and ChatScrollObserver Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/3、Chat-Observer Initialize ListObserverController and ChatScrollObserver for chat list observation. Configure the fixed position offset and a callback for rebuilding the scroll view. ```dart /// Initialize ListObserverController observerController = ListObserverController(controller: scrollController) ..cacheJumpIndexOffset = false; /// Initialize ChatScrollObserver chatObserver = ChatScrollObserver(observerController) // Greater than this offset will be fixed to the current chat position. ..fixedPositionOffset = 5 ..toRebuildScrollViewCallback = () { // Here you can use other way to rebuild the specified listView instead of [setState] setState(() {}); }; ``` -------------------------------- ### Configure ListView with ListViewObserver Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/3、Chat-Observer Configure the ListView with ChatObserverClampingScrollPhysics and wrap it with ListViewObserver. Ensure shrinkWrap is set according to the observer's state. ```dart Widget _buildListView() { Widget resultWidget = ListView.builder( physics: ChatObserverClampingScrollPhysics(observer: chatObserver), shrinkWrap: chatObserver.isShrinkWrap, reverse: true, controller: scrollController, ... ); resultWidget = ListViewObserver( controller: observerController, child: resultWidget, ); return resultWidget; } ``` -------------------------------- ### 手动触发 ListView 观察 Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/1、监听滚动视图中正在显示的子部件 当需要手动触发一次 ListView 的观察时,可以使用 ListViewOnceObserveNotification 并将其 dispatch 到目标 BuildContext。 ```dart ListViewOnceObserveNotification().dispatch(_sliverListViewContext); ``` -------------------------------- ### 使用 ListObserverController 手动触发观察 Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/1、监听滚动视图中正在显示的子部件 通过创建 ListObserverController 实例并将其传递给 ListViewObserver 的 controller 参数,可以手动调用 dispatchOnceObserve 方法来触发一次观察。这在需要主动获取滚动状态时非常有用。 ```dart // 创建 `ListObserverController` 实例 ListObserverController controller = ListObserverController(); ... // 传递给 `ListViewObserver` 的 `controller` 参数 ListViewObserver( ... controller: controller, ... ) ... // 手动触发一次观察 controller.dispatchOnceObserve(); ``` -------------------------------- ### Define Executable and Link Libraries Source: https://github.com/fluttercandies/flutter_scrollview_observer/blob/main/example/windows/runner/CMakeLists.txt Configures the main executable for the Windows runner, specifying source files, applying standard settings, defining preprocessor macros, linking necessary libraries, and setting include directories. It also adds a dependency on the flutter_assemble target. ```cmake cmake_minimum_required(VERSION 3.14) project(runner LANGUAGES CXX) add_executable(${BINARY_NAME} WIN32 "flutter_window.cpp" "main.cpp" "utils.cpp" "win32_window.cpp" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" "Runner.rc" "runner.exe.manifest" ) apply_standard_settings(${BINARY_NAME}) target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### 使用 ListViewObserver 监听 Sliver Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/1、监听滚动视图中正在显示的子部件 通过 ListViewObserver 包装 ListView,并提供 sliverListContexts 回调来指定要观察的 Sliver 的 BuildContext。onObserveAll 回调用于处理观察结果。 ```dart ListViewObserver( child: _buildListView(), sliverListContexts: () { return [if (_sliverListViewContext != null) _sliverListViewContext!]; }, onObserveAll: (resultMap) { final model = resultMap[_sliverListViewContext]; if (model == null) return; // 打印当前正在显示的第一个子部件 print('firstChild.index -- ${model.firstChild?.index}'); // 打印当前正在显示的所有子部件下标 print('displaying -- ${model.displayingChildIndexList}'); }, ) ``` -------------------------------- ### 常规方式使用 ListViewObserver Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/1、监听滚动视图中正在显示的子部件 将 ListViewObserver 作为父组件包裹 ListView,并通过 onObserve 回调获取滚动视图中第一个 Sliver 的观察结果。默认在 ListView 滚动时触发。 ```dart ListViewObserver( child: _buildListView(), onObserve: (resultModel) { print('firstChild.index -- ${resultModel.firstChild?.index}'); print('displaying -- ${resultModel.displayingChildIndexList}'); }, ) ``` -------------------------------- ### ListObserverController.dispatchOnceObserve 方法定义 Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/1、监听滚动视图中正在显示的子部件 该方法用于手动触发一次观察,并可以返回观察结果。支持通过 sliverContext 指定观察的滚动视图上下文,isForce 参数用于强制触发,isDependObserveCallback 参数控制是否依赖于 onObserve 回调的实现。 ```dart Future dispatchOnceObserve({ BuildContext? sliverContext, bool isForce = false, bool isDependObserveCallback = true, }) ``` -------------------------------- ### 记录 ListView 的 BuildContext Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/1、监听滚动视图中正在显示的子部件 在 ListView 的 itemBuilder 回调中记录当前 BuildContext。当存在多个 Sliver 时,此方法可能需要使用。 ```dart BuildContext? _sliverListViewContext; ListView _buildListView() { return ListView.separated( itemBuilder: (ctx, index) { if (_sliverListViewContext != ctx) { _sliverListViewContext = ctx; } ... }, ... ); } ``` -------------------------------- ### Scrolling with Dynamic Offset Calculation Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/2、Scrolling-to-the-specified-index-location Demonstrates how to use the `animateTo` method with a custom `offset` callback to handle dynamic scroll view heights, such as those with a SliverAppBar. ```dart observerController.animateTo( ... offset: (offset) { // The height of the SliverAppBar is calculated base on target offset and is returned in the current callback. // The observerController internally adjusts the appropriate offset based on the return value. return ObserverUtils.calcPersistentHeaderExtent( key: appBarKey, offset: offset, ); }, ); ``` -------------------------------- ### Import scrollview_observer Package Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/Home Import the necessary package in your Dart files where you intend to use the ScrollView observer functionality. ```dart import 'package:scrollview_observer/scrollview_observer.dart'; ``` -------------------------------- ### 使用 SliverViewObserver 观察 CustomScrollView 的 Viewport Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/1、监听滚动视图中正在显示的子部件 SliverViewObserver 用于观察 CustomScrollView 的 Viewport 中哪些指定的 Sliver 正在展示。sliverContexts 参数传入的是外层 Sliver 的 BuildContext。 ```dart SliverViewObserver( child: _buildScrollView(), sliverContexts: () { return [ if (grid1Context != null) grid1Context!, if (swipeContext != null) swipeContext!, if (grid2Context != null) grid2Context!, ]; }, onObserveViewport: (result) { firstChildCtxInViewport = result.firstChild.sliverContext; if (firstChildCtxInViewport == grid1Context) { debugPrint('current first sliver in viewport - gridView1'); } else if (firstChildCtxInViewport == swipeContext) { debugPrint('current first sliver in viewport - swipeView'); } else if (firstChildCtxInViewport == grid2Context) { debugPrint('current first sliver in viewport - gridView2'); } }, ) ``` -------------------------------- ### Configure Chat Observer for Specified Item Mode Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/3、Chat-Observer Use this configuration when dealing with discontinuous generative messages or simultaneous add/delete operations. Set `mode` to `.specified` and provide relevant `refItemIndex` values. ```dart chatObserver.standby( mode: ChatScrollObserverHandleMode.specified, refIndexType: ChatScrollObserverRefIndexType.relativeIndexStartFromCacheExtent, refItemIndex: 2, refItemIndexAfterUpdate: 2, ); ``` -------------------------------- ### Add scrollview_observer to pubspec.yaml Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/Home To use the scrollview_observer package, add it as a dependency in your pubspec.yaml file. Replace 'latest_version' with the actual latest version number. ```yaml dependencies: scrollview_observer: latest_version ``` -------------------------------- ### Set Initial Index with Model Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/2、滚动到指定下标位置 Configures the initial scroll index using `initialIndexModel` with an ObserverIndexPositionModel. This allows for more detailed control over the initial position, including alignment and fixed height. ```dart observerController = ListObserverController(controller: scrollController) ..initialIndexModel = ObserverIndexPositionModel( index: 10, isFixedHeight: true, alignment: 0.5, ); ``` -------------------------------- ### 自定义观察逻辑 Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/1、监听滚动视图中正在显示的子部件 使用 customHandleObserve 回调来自定义观察逻辑,当库自带的处理逻辑不满足需求时使用。 ```dart customHandleObserve: (context) { // 完全自定义你的观察逻辑 final _obj = ObserverUtils.findRenderObject(context); if (_obj is RenderSliverList) { ObserverCore.handleListObserve(context: context); } if (_obj is RenderSliverGrid || _obj is RenderSliverWaterfallFlow) { return ObserverCore.handleGridObserve(context: context); } return null; }, ``` -------------------------------- ### Observe Sliver Children with ListViewObserver and sliverListContexts Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/1、Observing-child-widgets-those-are-being-displayed-in-the-ScrollView Observe child widgets within specific Slivers using ListViewObserver by providing a function that returns a list of sliverContexts. The onObserveAll callback receives a map of results keyed by BuildContext. ```dart ListViewObserver( child: _buildListView(), sliverListContexts: () { return [if (_sliverListViewContext != null) _sliverListViewContext!]; }, onObserveAll: (resultMap) { final model = resultMap[_sliverListViewContext]; if (model == null) return; // Prints the first child widget index that is currently being displayed print('firstChild.index -- ${model.firstChild?.index}'); // Prints the index of all child widgets those are currently being displayed print('displaying -- ${model.displayingChildIndexList}'); }, ) ``` -------------------------------- ### Handling Dynamic Headers with Offset Parameter Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/2、滚动到指定下标位置 Use the offset parameter to manage scroll offsets when dealing with dynamic headers like SliverAppBar, ensuring correct positioning as the header's height changes. ```dart SliverAppBar( key: appBarKey, pinned: true, expandedHeight: 200, flexibleSpace: FlexibleSpaceBar( title: const Text('AppBar'), background: Container(color: Colors.orange), ), ); ``` ```dart observerController.animateTo( ... offset: (offset) { // 根据目标偏移量 offset,计算出 SliverAppBar 的高度并返回 // observerController 内部会根据该返回值做适当的偏移调整 return ObserverUtils.calcPersistentHeaderExtent( key: appBarKey, offset: offset, ); }, ); ``` -------------------------------- ### Record BuildContext for Sliver ListView Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/1、Observing-child-widgets-those-are-being-displayed-in-the-ScrollView Record the BuildContext of a ListView within its itemBuilder callback. This is necessary when using the specific Sliver observation method to identify the ListView. ```dart ListView _buildListView() { return ListView.separated( itemBuilder: (ctx, index) { if (_sliverListViewContext != ctx) { _sliverListViewContext = ctx; } ... }, ... ); } ``` -------------------------------- ### ObserverIndexPositionModel Definition Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/2、滚动到指定下标位置 Defines the parameters for configuring an initial scroll position, including index, context, height, alignment, offset, and padding. ```dart ObserverIndexPositionModel({ required this.index, this.sliverContext, this.isFixedHeight = false, this.alignment = 0, this.offset, this.padding = EdgeInsets.zero, }); ``` -------------------------------- ### Setting Padding for ScrollViewObserver Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/2、滚动到指定下标位置 When using padding with ListView or GridView, ensure the same padding value is provided to the observerController for accurate scrolling. ```dart ListView.separated(padding: _padding, ...); GridView.builder(padding: _padding, ...); ``` ```dart observerController.jumpTo(index: 1, padding: _padding); ``` -------------------------------- ### Jump to Index (No Animation) Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/2、Scrolling-to-the-specified-index-location Scrolls the ListView to the specified index without any animation. ```dart // Jump to the specified index position without animation. observerController.jumpTo(index: 1) ``` -------------------------------- ### Cache Extent Calculation Formula Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/3、Chat-Observer Formula for calculating cacheExtent to avoid issues when inserting many messages at once. Ensure the reference message view can be rendered. ```plaintext cacheExtent = [maximum height of a message] * [number of messages inserted at one time] + 200 ``` -------------------------------- ### Custom Observation Logic Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/1、Observing-child-widgets-those-are-being-displayed-in-the-ScrollView Implement customHandleObserve to define your own observation logic when the built-in methods are insufficient. It allows for custom handling of different RenderSliver types. ```dart customHandleObserve: (context) { // Here you can customize the observation logic. final _obj = ObserverUtils.findRenderObject(context); if (_obj is RenderSliverList) { ObserverCore.handleListObserve(context: context); } if (_obj is RenderSliverGrid || _obj is RenderSliverWaterfallFlow) { return ObserverCore.handleGridObserve(context: context); } return null; }, ``` -------------------------------- ### Manually Trigger ScrollView Observation with ListObserverController Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/1、Observing-child-widgets-those-are-being-displayed-in-the-ScrollView Manually trigger observations for a ScrollView using ListObserverController. Instantiate the controller, pass it to ListViewObserver, and then call dispatchOnceObserve() to force an observation. ```dart // Create an instance of [ListObserverController] ListObserverController controller = ListObserverController(); ... // Pass the controller instance to the 'controller' parameter of 'ListViewObserver' ListViewObserver( ... controller: controller, ... ) ... // Trigger an observation manually. controller.dispatchOnceObserve(); ``` -------------------------------- ### Animate to Index Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/2、Scrolling-to-the-specified-index-location Scrolls the ListView to the specified index with a smooth animation. ```dart // Jump to the specified index position with animation. observerController.animateTo( index: 1, duration: const Duration(milliseconds: 250), curve: Curves.ease, ); ``` -------------------------------- ### ObserverTriggerOnObserveType 枚举 Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/1、监听滚动视图中正在显示的子部件 配置触发 onObserve 和 onObserveAll 回调的前提条件,可以是直接返回数据或在显示项变化时返回。 ```dart enum ObserverTriggerOnObserveType { directly, displayingItemsChange, } ``` -------------------------------- ### Set Initial Index with Model Block Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/2、滚动到指定下标位置 Uses `initialIndexModelBlock` to dynamically provide an ObserverIndexPositionModel. This is useful when parameters like sliverContext are not available at initialization. ```dart observerController = SliverObserverController(controller: scrollController) ..initialIndexModelBlock = () { return ObserverIndexPositionModel( index: 6, sliverContext: _sliverListCtx, offset: calcPersistentHeaderExtent, ); }; ``` -------------------------------- ### 自定义目标 RenderSliver 类型 Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/1、监听滚动视图中正在显示的子部件 通过 customTargetRenderSliverType 回调,可以指定库需要处理的 RenderSliver 类型,以支持第三方库构建的列表。 ```dart customTargetRenderSliverType: (renderObj) { // 告诉该库它需要观察什么类型的RenderObject return renderObj is ExtendedRenderSliverList; }, ``` -------------------------------- ### Handle Multiple Message Insertions Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/3、Chat-Observer Insert multiple messages at once by passing the changeCount parameter to the standby method. This helps in managing the scroll position for bulk updates. ```dart _addMessage(int count) { chatObserver.standby(changeCount: count); setState(() { needIncrementUnreadMsgCount = true; for (var i = 0; i < count; i++) { chatModels.insert(0, ChatDataHelper.createChatModel()); } }); } ``` -------------------------------- ### Extended Observation Logic Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/1、Observing-child-widgets-those-are-being-displayed-in-the-ScrollView Use extendedHandleObserve to supplement the original observation logic, particularly for types like RenderSliverWaterfallFlow. Only supported by SliverViewObserver. ```dart extendedHandleObserve: (context) { // An extension of the original observation logic. final _obj = ObserverUtils.findRenderObject(context); if (_obj is RenderSliverWaterfallFlow) { return ObserverCore.handleGridObserve(context: context); } return null; }, ``` -------------------------------- ### ObserverAutoTriggerObserveType 枚举 Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/1、监听滚动视图中正在显示的子部件 定义了自动触发观察的时机,包括滚动开始、滚动更新和滚动结束。 ```dart enum ObserverAutoTriggerObserveType { scrollStart, scrollUpdate, scrollEnd, } ``` -------------------------------- ### Extend ScrollView Observation Logic Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/1、监听滚动视图中正在显示的子部件 Use `extendedHandleObserve` to supplement the default observation logic for specific RenderObjects like `RenderSliverWaterfallFlow`. ```dart extendedHandleObserve: (context) { // 在对原来的观察逻辑进行拓展 final _obj = ObserverUtils.findRenderObject(context); if (_obj is RenderSliverWaterfallFlow) { return ObserverCore.handleGridObserve(context: context); } return null; }, ``` -------------------------------- ### Chat Position Result Callback Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/3、Chat-Observer Callback for processing chat position results after handling scroll events. Used to display unread message bubbles. ```dart chatObserver = ChatScrollObserver(observerController) ..onHandlePositionResultCallback = (result) { switch (result.type) { case ChatScrollObserverHandlePositionType.keepPosition: // Keep the current chat position. // updateUnreadMsgCount(changeCount: result.changeCount); break; case ChatScrollObserverHandlePositionType.none: // Do nothing about the chat position. // updateUnreadMsgCount(isReset: true); break; } }; ``` -------------------------------- ### Set Minimum Observe Interval During Scrolling Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/1、监听滚动视图中正在显示的子部件 Configure `observeIntervalForScrolling` to set the minimum time between scroll observations, reducing observation frequency and improving performance. The default is `Duration.zero`. ```dart final Duration observeIntervalForScrolling; observerController.observeIntervalForScrolling = Duration(milliseconds: 500); ``` -------------------------------- ### ChatScrollObserverRefIndexType Enum Definition Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/3、Chat-Observer Defines different strategies for referencing items within the scroll view, crucial for accurate observer behavior during updates. Understand how `relativeIndexStartFromCacheExtent` and `relativeIndexStartFromDisplaying` calculate indices. ```dart enum ChatScrollObserverRefIndexType { /// relativeIndex trailing /// /// 6 | item16 | cacheExtent /// ----------------- ----------------- /// 5 | item15 | /// 4 | item14 | /// 3 | item13 | displaying /// 2 | item12 | /// 1 | item11 | /// ----------------- ----------------- /// 0 | item10 | cacheExtent <---- start /// /// leading relativeIndexStartFromCacheExtent, /// relativeIndex trailing /// /// 5 | item16 | cacheExtent /// ----------------- ----------------- /// 4 | item15 | /// 3 | item14 | /// 2 | item13 | displaying /// 1 | item12 | /// 0 | item11 | <---- start /// ----------------- ----------------- /// -1 | item10 | cacheExtent /// /// leading relativeIndexStartFromDisplaying, /// Directly specify the index of item. itemIndex, } ``` -------------------------------- ### Standby for Inserting or Removing Chat Data Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/3、Chat-Observer Call the standby method of ChatScrollObserver before inserting or removing chat data. Use isRemove flag for removal operations. ```dart onPressed: () { chatObserver.standby(); setState(() { chatModels.insert(0, ChatDataHelper.createChatModel()); }); }, ... onRemove: () { chatObserver.standby(isRemove: true); setState(() { chatModels.removeAt(index); }); }, ``` -------------------------------- ### Generative Message Position Keeping Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/3、Chat-Observer Adjust the processing mode in the standby method to 'generative' for keeping message position with generative messages like ChatGPT. This mode requires continuous generative messages. ```dart chatObserver.standby( mode: ChatScrollObserverHandleMode.generative, // changeCount: 1, ); ``` -------------------------------- ### Animate to Index in Sliver Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/2、Scrolling-to-the-specified-index-location Scrolls to a specific index within a particular sliver in a CustomScrollView. ```dart observerController.animateTo( sliverContext: _sliverViewCtx2, // _sliverViewCtx1 index: 10, duration: const Duration(milliseconds: 300), curve: Curves.easeInOut, ); ``` -------------------------------- ### Optimizing Scroll Performance with isFixedHeight Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/2、滚动到指定下标位置 Use the isFixedHeight parameter when child widgets have a fixed height to improve performance. This feature supports various ScrollView types since version 1.17.0. ```dart // 无动画滚动至下标位置 observerController.jumpTo(index: 150, isFixedHeight: true) ``` ```dart // 动画滚动至下标位置 observerController.animateTo( index: 150, isFixedHeight: true, duration: const Duration(milliseconds: 250), curve: Curves.ease, ); ``` -------------------------------- ### Reattach ScrollView Observer Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/1、监听滚动视图中正在显示的子部件 Call `reattach()` on the `observerController` when a scroll view is laid out conditionally after initialization, to ensure the observer can acquire its `BuildContext`. ```dart observerController.reattach(); ``` -------------------------------- ### Specifying Render Sliver Type for Third-Party ScrollViews Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/2、滚动到指定下标位置 For third-party ScrollViews, use the renderSliverType parameter to specify the rendering type (list or grid) if it's not a standard SliverList or SliverGrid. ```dart enum ObserverRenderSliverType { list, grid, } ``` ```dart observerController.jumpTo( index: 13, isFixedHeight: true, renderSliverType: ObserverRenderSliverType.grid, ); ``` -------------------------------- ### Clear Index Offset Cache Method Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/2、滚动到指定下标位置 Clears the offset cache used for jumping to a specified index. The sliverContext parameter is only needed when managing the ScrollView's BuildContext manually. ```dart /// Clear the offset cache that jumping to a specified index location. clearIndexOffsetCache(BuildContext? sliverContext) { ... ``` -------------------------------- ### ObserverTriggerOnObserveType Enum Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/1、Observing-child-widgets-those-are-being-displayed-in-the-ScrollView Defines when the onObserve callbacks are triggered. Defaults to displayingItemsChange. ```dart final ObserverTriggerOnObserveType triggerOnObserveType; enum ObserverTriggerOnObserveType { directly, displayingItemsChange, } ``` -------------------------------- ### Custom Target Render Sliver Type Source: https://github.com/fluttercandies/flutter_scrollview_observer/wiki/1、Observing-child-widgets-those-are-being-displayed-in-the-ScrollView Use customTargetRenderSliverType to specify the RenderSliver type for observation, useful for third-party packages. Only supported by ListViewObserver and GridViewObserver. ```dart customTargetRenderSliverType: (renderObj) { // Here you tell the package what type of RenderObject it needs to observe. return renderObj is ExtendedRenderSliverList; }, ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.