Add mouseCursor to RawScrollbar (#185750) ## Description Adds a `mouseCursor` property to `RawScrollbar`, allowing callers to customize the mouse cursor over the scrollbar's thumb/track via a `WidgetStateProperty<MouseCursor?>`. It resolves with `WidgetState.hovered` while the pointer is over the painted scrollbar, `WidgetState.dragged` while a thumb drag is active, and `WidgetState.disabled` while the scrollbar is not interactive. The override is gated to apply only while the pointer is over the painted scrollbar, using the same hit-test region that already drives hover behavior. When the pointer is anywhere else inside the scroll view's child, cursor resolution is deferred to ancestors, so a parent widget's cursor, such as an enclosing `EditableText`'s I-beam, is preserved. This is the core fix for the scenario described in #185733: today, the scrollbar's `MouseRegion` swallows the ancestor cursor for the entire scroll-view area. With this change, only the painted scrollbar surface participates in cursor resolution. When `mouseCursor` is null, or when its resolved value is null, `MouseCursor.defer` is used and ancestor cursors are left unchanged everywhere. The hover callbacks are only installed while the scrollbar is interactive, and the thumb drag recognizers only exist while the child is scrollable. When either stops being true the callbacks simply stop arriving, and a dropped drag recognizer is disposed without reporting a cancel, so the pointer state that feeds the cursor is released explicitly: when a mouse or trackpad thumb drag ends, when `interactive` changes, and when the child stops being scrollable. Without that, the resolved cursor could stay applied over the whole scroll view with no event left to clear it. One user-visible side effect worth calling out: after a mouse thumb drag that ends away from the scrollbar, the fade-out timer is no longer restarted by the following hover-exit, so the scrollbar can begin fading up to `timeToFade` earlier than before. That matches the behavior a touch drag already had. ## Why framework-only `flutter/flutter` is currently under a Material/Cupertino code freeze (#184093). Per the freeze guidance, the framework-side change can land now, and the corresponding `Scrollbar` / `ScrollbarThemeData` surfacing requested in #185733 will be ported to `material_ui` in `flutter/packages` once that repo opens for changes. This PR is therefore scoped to `lib/src/widgets/scrollbar.dart` and its widget-layer tests only. The framework API alone is enough to fix the reported scenario: an I-beam cursor over a `TextField`'s scrollable region remains intact when hovering content but switches over the scrollbar. See the test `RawScrollbar.mouseCursor only applies while the pointer is over the scrollbar`. This PR uses a non-closing `Refs #185733` so the issue stays open to track the remaining `Scrollbar` / `ScrollbarThemeData` work, which will land separately in `flutter/packages`. ## Tests Nine widget-layer tests in `test/widgets/scrollbar_test.dart`: - `RawScrollbar.mouseCursor only applies while the pointer is over the scrollbar` verifies an ancestor `MouseRegion(cursor: text)` keeps the I-beam over the content area, switches to the scrollbar's cursor over the thumb, yields back to the I-beam when leaving the scrollbar, and passes exactly `WidgetState.hovered` to the cursor resolver while hovering. - `RawScrollbar.mouseCursor resolves a WidgetStateProperty.fromMap` verifies the `WidgetStateProperty` contract end to end: hovered, dragged, map precedence, and the fallback back to the hovered entry on release. - `RawScrollbar without mouseCursor preserves the ancestor cursor over the scrollbar` verifies the default behavior: with no override set, the ancestor cursor wins everywhere, including over the scrollbar. - `RawScrollbar.mouseCursor updates when the property changes while hovered` verifies that prop changes during hover are picked up. - `RawScrollbar.mouseCursor stays applied while a thumb drag is active even when the pointer leaves the scrollbar` verifies that a dragged cursor remains stable during an active thumb drag. - `RawScrollbar.mouseCursor is released when a mouse drag ends off the scrollbar` verifies a single-pointer desktop drag: pressing the thumb, dragging into the content area, and releasing there hands the cursor straight back to the ancestor. - `RawScrollbar.mouseCursor is released when the scrollbar stops being interactive` verifies that flipping `interactive` to false, both while hovering and mid-drag, releases the override. - `RawScrollbar.mouseCursor is released when the child stops being scrollable` verifies that shrinking the child mid-drag releases the dragged state. - `RawScrollbar.mouseCursor clears dragged state when thumb drag is cancelled` verifies that cancellation resets the dragged cursor state. Each of the three release paths was confirmed to fail without its fix. Verification run locally: - `./bin/dart format --output=none --set-exit-if-changed packages/flutter/lib/src/widgets/scrollbar.dart packages/flutter/test/widgets/scrollbar_test.dart` - `./bin/flutter analyze --current-package --no-pub packages/flutter/lib/src/widgets/scrollbar.dart packages/flutter/test/widgets/scrollbar_test.dart` - `./bin/flutter test packages/flutter/test/widgets/scrollbar_test.dart` (112 passing) - `./bin/flutter test packages/flutter/test/widgets/` (7181 passing) - `./bin/flutter test packages/flutter/test/material/scrollbar_test.dart packages/flutter/test/cupertino/scrollbar_test.dart` and the other suites that build a scrollbar - `git diff --check upstream/master...HEAD` Refs #185733 --------- Co-authored-by: Tong Mu <dkwingsmt@users.noreply.github.com>
Flutter is Google's SDK for crafting beautiful, fast user experiences for mobile, web, and desktop from a single codebase. Flutter works with existing code, is used by developers and organizations around the world, and is free and open source.
For release and other announcements, join the flutter-announce mailing list. Our documentation also tracks breaking changes across releases.
The Flutter tool may occasionally download resources from Google servers. By downloading or using the Flutter SDK, you agree to the Google Terms of Service: https://policies.google.com/terms
For example, when installed from GitHub (as opposed to from a prepackaged archive), the Flutter tool will download the Dart SDK from Google servers immediately when first run, as it is used to execute the flutter tool itself. This will also occur when Flutter is upgraded (e.g. by running the flutter upgrade command).
We think Flutter will help you create beautiful, fast apps, with a productive, extensible and open development model, whether you're targeting iOS or Android, web, Windows, macOS, Linux or embedding it as the UI toolkit for a platform of your choice.
We want to enable designers to deliver their full creative vision without being forced to water it down due to limitations of the underlying framework. Flutter‘s layered architecture gives you control over every pixel on the screen and its powerful compositing capabilities let you overlay and animate graphics, video, text, and controls without limitation. Flutter includes a full set of widgets that deliver pixel-perfect experiences whether you’re building for iOS (Cupertino) or other platforms (Material), along with support for customizing or creating entirely new visual components.
Flutter is fast. It's powered by hardware-accelerated 2D graphics libraries like Skia (which underpins Chrome and Android) and Impeller. We architected Flutter to support glitch-free, jank-free graphics at the native speed of your device.
Flutter code is powered by the world-class Dart programming language, which enables compilation to 32-bit and 64-bit ARM machine code for iOS and Android, JavaScript and WebAssembly for the web, as well as Intel x64 and ARM for desktop devices.
Flutter offers stateful hot reload, allowing you to make changes to your code and see the results instantly without restarting your app or losing its state.
Flutter works with any development tool (or none at all), and also includes editor plug-ins for both Visual Studio Code and IntelliJ / Android Studio. Flutter provides tens of thousands of packages to speed your development, regardless of your target platform. And accessing other native code is easy, with support for both FFI (on Android, on iOS, on macOS, and on Windows) as well as platform-specific APIs.
Flutter is a fully open-source project, and we welcome contributions. Information on how to get started can be found in our contributor guide.