flutter/examples/api/lib/widgets
Hans Muller 92f8455ff8
Scrollbar thumb drag gestures now produce one start and one end scroll notification (#146654)
The scroll notification events reported for a press-drag-release gesture within a scrollable on a touch screen device begin with a `ScrollStartNotification`, followed by a series of `ScrollUpdateNotifications`, and conclude with a `ScrollEndNotification`. This protocol can be used to defer work until an interactive scroll gesture ends. For example, you might defer updating a scrollable's contents via network requests until the scroll has ended, or you might want to automatically auto-scroll at that time. 

In the example that follows the CustomScrollView automatically scrolls so that the last partially visible fixed-height item is completely visible when the scroll gesture ends. Many iOS applications do this kind of thing. It only makes sense to auto-scroll when the user isn't actively dragging the scrollable around.

It's easy enough to do this by reacting to a ScrollEndNotifcation by auto-scrolling to align the last fixed-height list item ([source code](https://gist.github.com/HansMuller/13e2a7adadc9afb3803ba7848b20c410)).

https://github.com/flutter/flutter/assets/1377460/a6e6fc77-6742-4f98-81ba-446536535f73

Dragging the scrollbar thumb in a desktop application is a similar user gesture. Currently it's not possible to defer work or auto-scroll (or whatever) while the scrollable is actively being dragged via the scrollbar thumb because each scrollbar thumb motion is mapped to a scroll start - scroll update - scroll end series of notifications.  On a desktop platform, the same code behaves quite differently when the scrollbar thumb is dragged.

https://github.com/flutter/flutter/assets/1377460/2593d8a3-639c-407f-80c1-6e6f67fb8c5f

The stream of scroll-end events triggers auto-scrolling every time the thumb moves. From the user's perspective this feels like a losing struggle.

One can also detect the beginning and end of a touch-drag by listening to the value of a ScrollPosition's `isScrollingNotifier`. This approach suffers from a similar problem: during a scrollbar thumb-drag, the `isScrollingNotifier` value isn't updated at all.

This PR refactors the RawScrollbar implementation to effectively use a ScrollDragController to manage scrolls caused by dragging the scrollbar's thumb. Doing so means that dragging the thumb will produce the same notifications as dragging the scrollable on a touch device.

Now desktop applications can choose to respond to scrollbar thumb drags in the same that they respond to drag scrolling on a touch screen. With the changes included here, the desktop or web version of the app works as expected, whether you're listing to scroll notifications or the scroll position's `isScrollingNotifier`.

https://github.com/flutter/flutter/assets/1377460/67435c40-a866-4735-a19b-e3d68eac8139

This PR also makes the second [ScrollPosition API doc example](https://api.flutter.dev/flutter/widgets/ScrollPosition-class.html#cupertino.ScrollPosition.2) work as expected when used with the DartPad that's  part of API doc page.

Desktop applications also see scroll start-update-end notifications due to the mouse wheel.  There is no touch screen analog for the mouse wheel, so an application that wanted to enable this kind of auto-scrolling alignment would have to include a heuristic that dealt with the sequence of small scrolls triggered by the mouse wheel. Here's an example of that: [source code](https://gist.github.com/HansMuller/ce5c474a458f5f4bcc07b0d621843165). This version of the app does not auto-align in response to small changes, wether they're triggered by dragging the scrollbar thumb of the mouse wheel.

Related sliver utility PRs: https://github.com/flutter/flutter/pull/143538,  https://github.com/flutter/flutter/pull/143196, https://github.com/flutter/flutter/pull/143325.
2024-06-04 22:02:12 +00:00
..
actions Add tests for actions.0.dart API example. (#148678) 2024-05-22 07:25:21 +00:00
animated_grid Rename Sample classes (#124080) 2023-04-04 20:34:29 +00:00
animated_list Rename Sample classes (#124080) 2023-04-04 20:34:29 +00:00
animated_size Add test for animated_size.0.dart API example. (#147828) 2024-05-10 21:55:51 +00:00
animated_switcher Add tests for animated_switcher.0.dart API example. (#149180) 2024-05-29 12:10:34 +00:00
app Rename Sample classes (#124080) 2023-04-04 20:34:29 +00:00
app_lifecycle_listener Update misc tests for Material3 (#128712) 2023-06-13 08:57:27 -07:00
async Add tests for stream_builder.0.dart API example. (#147832) 2024-05-10 21:48:35 +00:00
autocomplete Rename Sample classes (#124080) 2023-04-04 20:34:29 +00:00
autofill Rename Sample classes (#124080) 2023-04-04 20:34:29 +00:00
basic Update collection-fors to prefer final (as per updated prefer_final_in_for_each) (#127511) 2023-05-26 23:34:36 +00:00
binding Rename Sample classes (#124080) 2023-04-04 20:34:29 +00:00
color_filter Rename Sample classes (#124080) 2023-04-04 20:34:29 +00:00
dismissible Rename Sample classes (#124080) 2023-04-04 20:34:29 +00:00
drag_target Deprecates onWillAccept and onAccept callbacks in DragTarget. (#133691) 2023-11-10 22:47:22 +00:00
draggable_scrollable_sheet Reland "Reland - Introduce tone-based surfaces and accent color add-ons - Part 2" (#144273) 2024-02-28 13:55:50 -08:00
editable_text Add more documentation for TextEditingController default constructor (#143452) 2024-02-14 20:10:18 +00:00
focus_manager Turning if chains into shorter switch statements (#144977) 2024-03-13 17:16:17 +00:00
focus_scope improve focus example (#147464) 2024-05-07 20:07:49 +00:00
focus_traversal Rename Sample classes (#124080) 2023-04-04 20:34:29 +00:00
form Reapply new PopScope API (#147607) 2024-05-07 09:04:49 -07:00
framework Rename Sample classes (#124080) 2023-04-04 20:34:29 +00:00
gesture_detector Rename Sample classes (#124080) 2023-04-04 20:34:29 +00:00
hardware_keyboard cleanup now-irrelevant ignores for deprecated_member_use (#143403) 2024-02-14 21:08:25 +00:00
heroes Dev, examples/api, etc updated for Material 3 by default (#129683) 2023-06-28 09:41:58 -07:00
image Rename Sample classes (#124080) 2023-04-04 20:34:29 +00:00
implicit_animations Add test for animated_fractionally_sized_box.0.dart API example. (#146721) 2024-05-01 16:03:12 +00:00
inherited_model Rename Sample classes (#124080) 2023-04-04 20:34:29 +00:00
inherited_notifier Rename Sample classes (#124080) 2023-04-04 20:34:29 +00:00
inherited_theme Rename Sample classes (#124080) 2023-04-04 20:34:29 +00:00
interactive_viewer Update links and surrounding text for new main-api docs (#138602) 2023-11-17 22:27:53 +00:00
layout_builder Rename Sample classes (#124080) 2023-04-04 20:34:29 +00:00
magnifier Remove dead code (#126266) 2023-05-09 15:47:16 +00:00
media_query Rename Sample classes (#124080) 2023-04-04 20:34:29 +00:00
navigator Rename Sample classes (#124080) 2023-04-04 20:34:29 +00:00
navigator_pop_handler Refactors page API (#137792) 2024-05-13 22:45:51 +00:00
nested_scroll_view Rename Sample classes (#124080) 2023-04-04 20:34:29 +00:00
notification_listener Rename Sample classes (#124080) 2023-04-04 20:34:29 +00:00
overflow_bar Rename Sample classes (#124080) 2023-04-04 20:34:29 +00:00
overlay switch expressions: finale (#148711) 2024-05-21 16:18:05 +00:00
overscroll_indicator Rename Sample classes (#124080) 2023-04-04 20:34:29 +00:00
page Refactors page API (#137792) 2024-05-13 22:45:51 +00:00
page_storage Rename Sample classes (#124080) 2023-04-04 20:34:29 +00:00
page_view Reland "Reland - Introduce tone-based surfaces and accent color add-ons - Part 2" (#144273) 2024-02-28 13:55:50 -08:00
pop_scope Reapply new PopScope API (#147607) 2024-05-07 09:04:49 -07:00
preferred_size Rename Sample classes (#124080) 2023-04-04 20:34:29 +00:00
restoration Rename Sample classes (#124080) 2023-04-04 20:34:29 +00:00
restoration_properties Add tests for restorable_value.0.dart API example. (#148676) 2024-05-23 08:34:23 +00:00
routes Update RouteObserver example and fix an error thrown (#141166) 2024-01-09 20:48:56 +00:00
scroll_end_notification Scrollbar thumb drag gestures now produce one start and one end scroll notification (#146654) 2024-06-04 22:02:12 +00:00
scroll_notification_observer Add ScrollNotificationObserver sample (#127023) 2023-05-25 15:58:52 +00:00
scroll_position Scrollbar thumb drag gestures now produce one start and one end scroll notification (#146654) 2024-06-04 22:02:12 +00:00
scroll_view Use super.key instead of manually passing the Key parameter to the parent class (#147621) 2024-05-13 22:12:49 +00:00
scrollbar Rename Sample classes (#124080) 2023-04-04 20:34:29 +00:00
shared_app_data Add tests for shared_app_data.#.dart API examples. (#147830) 2024-05-20 17:49:04 +00:00
shortcuts Add tests for single_activator.0.dart API example. (#147426) 2024-05-01 14:52:57 +00:00
single_child_scroll_view Rename Sample classes (#124080) 2023-04-04 20:34:29 +00:00
sliver Fix DecoratedSliver sample code to reflect the description (#148621) 2024-05-23 08:52:15 +00:00
sliver_fill Rename Sample classes (#124080) 2023-04-04 20:34:29 +00:00
slotted_render_object_widget Replace RenderBox.compute* with RenderBox.get* and add @visibleForOverriding (#145503) 2024-03-22 02:44:55 +00:00
system_context_menu Reland Native ios context menu (#143002) (#148238) (#148265) 2024-05-15 18:37:05 +00:00
table Rename Sample classes (#124080) 2023-04-04 20:34:29 +00:00
tap_region Rename Sample classes (#124080) 2023-04-04 20:34:29 +00:00
text Rename Sample classes (#124080) 2023-04-04 20:34:29 +00:00
text_magnifier Updated TextMagnifierExampleApp to M3 (#129381) 2023-06-26 10:44:11 -07:00
transitions Test remaining transitions api examples (#148302) 2024-05-23 18:57:14 +00:00
tween_animation_builder Add tests for tween_animation_builder.0.dart API example. (#148902) 2024-05-30 20:17:04 +00:00
undo_history Rename Sample classes (#124080) 2023-04-04 20:34:29 +00:00
value_listenable_builder Remove deprecated TextTheme members (#139255) 2024-03-28 01:20:55 +00:00