From 1ccad1a2a7fb682b1bad955e9019d4bad0ec95b6 Mon Sep 17 00:00:00 2001 From: Qun Cheng <36861262+QuncCccccc@users.noreply.github.com> Date: Wed, 13 Mar 2024 16:31:50 +0000 Subject: [PATCH] Remove `showTrackOnHover` from `Scrollbar` and `ScrollbarTheme` (#144180) This PR is to remove deprecated `Scrollbar.showTrackOnHover` and `ScrollbarThemeData.showTrackOnHover`. These parameters are made obsolete in https://github.com/flutter/flutter/pull/111706. Part of https://github.com/flutter/flutter/issues/143956 --- .../flutter/lib/src/material/scrollbar.dart | 29 ----------- .../lib/src/material/scrollbar_theme.dart | 27 +---------- .../flutter/test/material/scrollbar_test.dart | 18 +++++-- .../test/material/scrollbar_theme_test.dart | 48 ++++++++++++++----- 4 files changed, 52 insertions(+), 70 deletions(-) diff --git a/packages/flutter/lib/src/material/scrollbar.dart b/packages/flutter/lib/src/material/scrollbar.dart index 561c3917dd4..5f7393fb891 100644 --- a/packages/flutter/lib/src/material/scrollbar.dart +++ b/packages/flutter/lib/src/material/scrollbar.dart @@ -95,11 +95,6 @@ class Scrollbar extends StatelessWidget { this.notificationPredicate, this.interactive, this.scrollbarOrientation, - @Deprecated( - 'Use ScrollbarThemeData.trackVisibility to resolve based on the current state instead. ' - 'This feature was deprecated after v3.4.0-19.0.pre.', - ) - this.showTrackOnHover, }); /// {@macro flutter.widgets.Scrollbar.child} @@ -128,24 +123,8 @@ class Scrollbar extends StatelessWidget { /// If the track visibility is related to the scrollbar's material state, /// use the global [ScrollbarThemeData.trackVisibility] or override the /// sub-tree's theme data. - /// - /// Replaces deprecated [showTrackOnHover]. final bool? trackVisibility; - /// Controls if the track will show on hover and remain, including during drag. - /// - /// If this property is null, then [ScrollbarThemeData.showTrackOnHover] of - /// [ThemeData.scrollbarTheme] is used. If that is also null, the default value - /// is false. - /// - /// This is deprecated, [trackVisibility] or [ScrollbarThemeData.trackVisibility] - /// should be used instead. - @Deprecated( - 'Use ScrollbarThemeData.trackVisibility to resolve based on the current state instead. ' - 'This feature was deprecated after v3.4.0-19.0.pre.', - ) - final bool? showTrackOnHover; - /// The thickness of the scrollbar in the cross axis of the scrollable. /// /// If null, the default value is platform dependent. On [TargetPlatform.android], @@ -190,7 +169,6 @@ class Scrollbar extends StatelessWidget { controller: controller, thumbVisibility: thumbVisibility, trackVisibility: trackVisibility, - showTrackOnHover: showTrackOnHover, thickness: thickness, radius: radius, notificationPredicate: notificationPredicate, @@ -207,7 +185,6 @@ class _MaterialScrollbar extends RawScrollbar { super.controller, super.thumbVisibility, super.trackVisibility, - this.showTrackOnHover, super.thickness, super.radius, ScrollNotificationPredicate? notificationPredicate, @@ -220,8 +197,6 @@ class _MaterialScrollbar extends RawScrollbar { notificationPredicate: notificationPredicate ?? defaultScrollNotificationPredicate, ); - final bool? showTrackOnHover; - @override _MaterialScrollbarState createState() => _MaterialScrollbarState(); } @@ -241,12 +216,8 @@ class _MaterialScrollbarState extends RawScrollbarState<_MaterialScrollbar> { @override bool get enableGestures => widget.interactive ?? _scrollbarTheme.interactive ?? !_useAndroidScrollbar; - bool get _showTrackOnHover => widget.showTrackOnHover ?? _scrollbarTheme.showTrackOnHover ?? false; MaterialStateProperty get _trackVisibility => MaterialStateProperty.resolveWith((Set states) { - if (states.contains(MaterialState.hovered) && _showTrackOnHover) { - return true; - } return widget.trackVisibility ?? _scrollbarTheme.trackVisibility?.resolve(states) ?? false; }); diff --git a/packages/flutter/lib/src/material/scrollbar_theme.dart b/packages/flutter/lib/src/material/scrollbar_theme.dart index 5cee3bfd454..175fa0b60d4 100644 --- a/packages/flutter/lib/src/material/scrollbar_theme.dart +++ b/packages/flutter/lib/src/material/scrollbar_theme.dart @@ -45,11 +45,6 @@ class ScrollbarThemeData with Diagnosticable { this.mainAxisMargin, this.minThumbLength, this.interactive, - @Deprecated( - 'Use ScrollbarThemeData.trackVisibility to resolve based on the current state instead. ' - 'This feature was deprecated after v3.4.0-19.0.pre.', - ) - this.showTrackOnHover, }); /// Overrides the default value of [Scrollbar.thumbVisibility] in all @@ -67,14 +62,6 @@ class ScrollbarThemeData with Diagnosticable { /// descendant [Scrollbar] widgets. final MaterialStateProperty? trackVisibility; - /// Overrides the default value of [Scrollbar.showTrackOnHover] in all - /// descendant [Scrollbar] widgets. - @Deprecated( - 'Use ScrollbarThemeData.trackVisibility to resolve based on the current state instead. ' - 'This feature was deprecated after v3.4.0-19.0.pre.', - ) - final bool? showTrackOnHover; - /// Overrides the default value of [Scrollbar.interactive] in all /// descendant [Scrollbar] widgets. final bool? interactive; @@ -92,14 +79,14 @@ class ScrollbarThemeData with Diagnosticable { final MaterialStateProperty? thumbColor; /// Overrides the default [Color] of the [Scrollbar] track when - /// [showTrackOnHover] is true in all descendant [Scrollbar] widgets. + /// [trackVisibility] is true in all descendant [Scrollbar] widgets. /// /// Resolves in the following states: /// * [MaterialState.hovered] on web and desktop platforms. final MaterialStateProperty? trackColor; /// Overrides the default [Color] of the [Scrollbar] track border when - /// [showTrackOnHover] is true in all descendant [Scrollbar] widgets. + /// [trackVisibility] is true in all descendant [Scrollbar] widgets. /// /// Resolves in the following states: /// * [MaterialState.hovered] on web and desktop platforms. @@ -148,17 +135,11 @@ class ScrollbarThemeData with Diagnosticable { double? crossAxisMargin, double? mainAxisMargin, double? minThumbLength, - @Deprecated( - 'Use ScrollbarThemeData.trackVisibility to resolve based on the current state instead. ' - 'This feature was deprecated after v3.4.0-19.0.pre.', - ) - bool? showTrackOnHover, }) { return ScrollbarThemeData( thumbVisibility: thumbVisibility ?? this.thumbVisibility, thickness: thickness ?? this.thickness, trackVisibility: trackVisibility ?? this.trackVisibility, - showTrackOnHover: showTrackOnHover ?? this.showTrackOnHover, interactive: interactive ?? this.interactive, radius: radius ?? this.radius, thumbColor: thumbColor ?? this.thumbColor, @@ -181,7 +162,6 @@ class ScrollbarThemeData with Diagnosticable { thumbVisibility: MaterialStateProperty.lerp(a?.thumbVisibility, b?.thumbVisibility, t, _lerpBool), thickness: MaterialStateProperty.lerp(a?.thickness, b?.thickness, t, lerpDouble), trackVisibility: MaterialStateProperty.lerp(a?.trackVisibility, b?.trackVisibility, t, _lerpBool), - showTrackOnHover: _lerpBool(a?.showTrackOnHover, b?.showTrackOnHover, t), interactive: _lerpBool(a?.interactive, b?.interactive, t), radius: Radius.lerp(a?.radius, b?.radius, t), thumbColor: MaterialStateProperty.lerp(a?.thumbColor, b?.thumbColor, t, Color.lerp), @@ -198,7 +178,6 @@ class ScrollbarThemeData with Diagnosticable { thumbVisibility, thickness, trackVisibility, - showTrackOnHover, interactive, radius, thumbColor, @@ -221,7 +200,6 @@ class ScrollbarThemeData with Diagnosticable { && other.thumbVisibility == thumbVisibility && other.thickness == thickness && other.trackVisibility == trackVisibility - && other.showTrackOnHover == showTrackOnHover && other.interactive == interactive && other.radius == radius && other.thumbColor == thumbColor @@ -238,7 +216,6 @@ class ScrollbarThemeData with Diagnosticable { properties.add(DiagnosticsProperty>('thumbVisibility', thumbVisibility, defaultValue: null)); properties.add(DiagnosticsProperty>('thickness', thickness, defaultValue: null)); properties.add(DiagnosticsProperty>('trackVisibility', trackVisibility, defaultValue: null)); - properties.add(DiagnosticsProperty('showTrackOnHover', showTrackOnHover, defaultValue: null)); properties.add(DiagnosticsProperty('interactive', interactive, defaultValue: null)); properties.add(DiagnosticsProperty('radius', radius, defaultValue: null)); properties.add(DiagnosticsProperty>('thumbColor', thumbColor, defaultValue: null)); diff --git a/packages/flutter/test/material/scrollbar_test.dart b/packages/flutter/test/material/scrollbar_test.dart index a1fd4ad891e..f3ff9ff141a 100644 --- a/packages/flutter/test/material/scrollbar_test.dart +++ b/packages/flutter/test/material/scrollbar_test.dart @@ -1020,7 +1020,12 @@ void main() { useMaterial3: false, scrollbarTheme: ScrollbarThemeData( thumbVisibility: MaterialStateProperty.all(true), - showTrackOnHover: true, + trackVisibility: MaterialStateProperty.resolveWith((Set states) { + if (states.contains(MaterialState.hovered)) { + return true; + } + return false; + }) ), ), home: const SingleChildScrollView( @@ -1160,7 +1165,7 @@ void main() { }), ); - testWidgets('ScrollbarThemeData.trackVisibility replaces showTrackOnHover', (WidgetTester tester) async { + testWidgets('ScrollbarThemeData.trackVisibility', (WidgetTester tester) async { await tester.pumpWidget( MaterialApp( theme: ThemeData( @@ -1228,14 +1233,19 @@ void main() { }), ); - testWidgets('Scrollbar showTrackOnHover', (WidgetTester tester) async { + testWidgets('Scrollbar trackVisibility on hovered', (WidgetTester tester) async { await tester.pumpWidget( MaterialApp( theme: ThemeData( useMaterial3: false, scrollbarTheme: ScrollbarThemeData( thumbVisibility: MaterialStateProperty.all(true), - showTrackOnHover: true, + trackVisibility: MaterialStateProperty.resolveWith((Set states) { + if (states.contains(MaterialState.hovered)) { + return true; + } + return false; + }), ), ), home: const SingleChildScrollView( diff --git a/packages/flutter/test/material/scrollbar_theme_test.dart b/packages/flutter/test/material/scrollbar_theme_test.dart index 642cab7aa68..a74df913ac2 100644 --- a/packages/flutter/test/material/scrollbar_theme_test.dart +++ b/packages/flutter/test/material/scrollbar_theme_test.dart @@ -33,12 +33,21 @@ void main() { final ScrollController scrollController = ScrollController(); await tester.pumpWidget( MaterialApp( - theme: ThemeData(useMaterial3: false), + theme: ThemeData( + useMaterial3: false, + scrollbarTheme: ScrollbarThemeData( + trackVisibility: MaterialStateProperty.resolveWith((Set states) { + if (states.contains(MaterialState.hovered)) { + return true; + } + return false; + }) + ) + ), home: ScrollConfiguration( behavior: const NoScrollbarBehavior(), child: Scrollbar( thumbVisibility: true, - showTrackOnHover: true, controller: scrollController, child: SingleChildScrollView( controller: scrollController, @@ -363,7 +372,6 @@ void main() { testWidgets('Scrollbar widget properties take priority over theme', (WidgetTester tester) async { const double thickness = 4.0; const double edgeMargin = 2.0; - const bool showTrackOnHover = true; const Radius radius = Radius.circular(3.0); final ScrollController scrollController = ScrollController(); @@ -371,13 +379,20 @@ void main() { MaterialApp( theme: ThemeData( colorScheme: const ColorScheme.light(), + scrollbarTheme: ScrollbarThemeData( + trackVisibility: MaterialStateProperty.resolveWith((Set states) { + if (states.contains(MaterialState.hovered)) { + return true; + } + return false; + }) + ), ), home: ScrollConfiguration( behavior: const NoScrollbarBehavior(), child: Scrollbar( thickness: thickness, thumbVisibility: true, - showTrackOnHover: showTrackOnHover, radius: radius, controller: scrollController, child: SingleChildScrollView( @@ -465,15 +480,24 @@ void main() { testWidgets('ThemeData colorScheme is used when no ScrollbarTheme is set', (WidgetTester tester) async { (ScrollController, Widget) buildFrame(ThemeData appTheme) { final ScrollController scrollController = ScrollController(); + final ThemeData theme = appTheme.copyWith( + scrollbarTheme: ScrollbarThemeData( + trackVisibility: MaterialStateProperty.resolveWith((Set states) { + if (states.contains(MaterialState.hovered)) { + return true; + } + return false; + }) + ), + ); return ( scrollController, MaterialApp( - theme: appTheme, + theme: theme, home: ScrollConfiguration( behavior: const NoScrollbarBehavior(), child: Scrollbar( thumbVisibility: true, - showTrackOnHover: true, controller: scrollController, child: SingleChildScrollView( controller: scrollController, @@ -654,7 +678,6 @@ void main() { behavior: const NoScrollbarBehavior(), child: Scrollbar( thumbVisibility: true, - showTrackOnHover: true, controller: scrollController, child: SingleChildScrollView( controller: scrollController, @@ -702,7 +725,6 @@ void main() { final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); ScrollbarThemeData( thickness: MaterialStateProperty.resolveWith(_getThickness), - showTrackOnHover: true, thumbVisibility: MaterialStateProperty.resolveWith(_getThumbVisibility), radius: const Radius.circular(3.0), thumbColor: MaterialStateProperty.resolveWith(_getThumbColor), @@ -721,7 +743,6 @@ void main() { expect(description, [ "thumbVisibility: Instance of '_MaterialStatePropertyWith'", "thickness: Instance of '_MaterialStatePropertyWith'", - 'showTrackOnHover: true', 'radius: Radius.circular(3.0)', "thumbColor: Instance of '_MaterialStatePropertyWith'", "trackColor: Instance of '_MaterialStatePropertyWith'", @@ -749,7 +770,6 @@ class NoScrollbarBehavior extends ScrollBehavior { ScrollbarThemeData _scrollbarTheme({ MaterialStateProperty? thickness, MaterialStateProperty? trackVisibility, - bool showTrackOnHover = true, MaterialStateProperty? thumbVisibility, Radius radius = const Radius.circular(6.0), MaterialStateProperty? thumbColor, @@ -761,8 +781,12 @@ ScrollbarThemeData _scrollbarTheme({ }) { return ScrollbarThemeData( thickness: thickness ?? MaterialStateProperty.resolveWith(_getThickness), - trackVisibility: trackVisibility, - showTrackOnHover: showTrackOnHover, + trackVisibility: trackVisibility ?? MaterialStateProperty.resolveWith((Set states) { + if (states.contains(MaterialState.hovered)) { + return true; + } + return false; + }), thumbVisibility: thumbVisibility, radius: radius, thumbColor: thumbColor ?? MaterialStateProperty.resolveWith(_getThumbColor),