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
This commit is contained in:
Qun Cheng 2024-03-13 16:31:50 +00:00 committed by GitHub
parent 59da4dea15
commit 1ccad1a2a7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 52 additions and 70 deletions

View file

@ -95,11 +95,6 @@ class Scrollbar extends StatelessWidget {
this.notificationPredicate, this.notificationPredicate,
this.interactive, this.interactive,
this.scrollbarOrientation, 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} /// {@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, /// If the track visibility is related to the scrollbar's material state,
/// use the global [ScrollbarThemeData.trackVisibility] or override the /// use the global [ScrollbarThemeData.trackVisibility] or override the
/// sub-tree's theme data. /// sub-tree's theme data.
///
/// Replaces deprecated [showTrackOnHover].
final bool? trackVisibility; 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. /// The thickness of the scrollbar in the cross axis of the scrollable.
/// ///
/// If null, the default value is platform dependent. On [TargetPlatform.android], /// If null, the default value is platform dependent. On [TargetPlatform.android],
@ -190,7 +169,6 @@ class Scrollbar extends StatelessWidget {
controller: controller, controller: controller,
thumbVisibility: thumbVisibility, thumbVisibility: thumbVisibility,
trackVisibility: trackVisibility, trackVisibility: trackVisibility,
showTrackOnHover: showTrackOnHover,
thickness: thickness, thickness: thickness,
radius: radius, radius: radius,
notificationPredicate: notificationPredicate, notificationPredicate: notificationPredicate,
@ -207,7 +185,6 @@ class _MaterialScrollbar extends RawScrollbar {
super.controller, super.controller,
super.thumbVisibility, super.thumbVisibility,
super.trackVisibility, super.trackVisibility,
this.showTrackOnHover,
super.thickness, super.thickness,
super.radius, super.radius,
ScrollNotificationPredicate? notificationPredicate, ScrollNotificationPredicate? notificationPredicate,
@ -220,8 +197,6 @@ class _MaterialScrollbar extends RawScrollbar {
notificationPredicate: notificationPredicate ?? defaultScrollNotificationPredicate, notificationPredicate: notificationPredicate ?? defaultScrollNotificationPredicate,
); );
final bool? showTrackOnHover;
@override @override
_MaterialScrollbarState createState() => _MaterialScrollbarState(); _MaterialScrollbarState createState() => _MaterialScrollbarState();
} }
@ -241,12 +216,8 @@ class _MaterialScrollbarState extends RawScrollbarState<_MaterialScrollbar> {
@override @override
bool get enableGestures => widget.interactive ?? _scrollbarTheme.interactive ?? !_useAndroidScrollbar; bool get enableGestures => widget.interactive ?? _scrollbarTheme.interactive ?? !_useAndroidScrollbar;
bool get _showTrackOnHover => widget.showTrackOnHover ?? _scrollbarTheme.showTrackOnHover ?? false;
MaterialStateProperty<bool> get _trackVisibility => MaterialStateProperty.resolveWith((Set<MaterialState> states) { MaterialStateProperty<bool> get _trackVisibility => MaterialStateProperty.resolveWith((Set<MaterialState> states) {
if (states.contains(MaterialState.hovered) && _showTrackOnHover) {
return true;
}
return widget.trackVisibility ?? _scrollbarTheme.trackVisibility?.resolve(states) ?? false; return widget.trackVisibility ?? _scrollbarTheme.trackVisibility?.resolve(states) ?? false;
}); });

View file

@ -45,11 +45,6 @@ class ScrollbarThemeData with Diagnosticable {
this.mainAxisMargin, this.mainAxisMargin,
this.minThumbLength, this.minThumbLength,
this.interactive, 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 /// Overrides the default value of [Scrollbar.thumbVisibility] in all
@ -67,14 +62,6 @@ class ScrollbarThemeData with Diagnosticable {
/// descendant [Scrollbar] widgets. /// descendant [Scrollbar] widgets.
final MaterialStateProperty<bool?>? trackVisibility; final MaterialStateProperty<bool?>? 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 /// Overrides the default value of [Scrollbar.interactive] in all
/// descendant [Scrollbar] widgets. /// descendant [Scrollbar] widgets.
final bool? interactive; final bool? interactive;
@ -92,14 +79,14 @@ class ScrollbarThemeData with Diagnosticable {
final MaterialStateProperty<Color?>? thumbColor; final MaterialStateProperty<Color?>? thumbColor;
/// Overrides the default [Color] of the [Scrollbar] track when /// 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: /// Resolves in the following states:
/// * [MaterialState.hovered] on web and desktop platforms. /// * [MaterialState.hovered] on web and desktop platforms.
final MaterialStateProperty<Color?>? trackColor; final MaterialStateProperty<Color?>? trackColor;
/// Overrides the default [Color] of the [Scrollbar] track border when /// 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: /// Resolves in the following states:
/// * [MaterialState.hovered] on web and desktop platforms. /// * [MaterialState.hovered] on web and desktop platforms.
@ -148,17 +135,11 @@ class ScrollbarThemeData with Diagnosticable {
double? crossAxisMargin, double? crossAxisMargin,
double? mainAxisMargin, double? mainAxisMargin,
double? minThumbLength, 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( return ScrollbarThemeData(
thumbVisibility: thumbVisibility ?? this.thumbVisibility, thumbVisibility: thumbVisibility ?? this.thumbVisibility,
thickness: thickness ?? this.thickness, thickness: thickness ?? this.thickness,
trackVisibility: trackVisibility ?? this.trackVisibility, trackVisibility: trackVisibility ?? this.trackVisibility,
showTrackOnHover: showTrackOnHover ?? this.showTrackOnHover,
interactive: interactive ?? this.interactive, interactive: interactive ?? this.interactive,
radius: radius ?? this.radius, radius: radius ?? this.radius,
thumbColor: thumbColor ?? this.thumbColor, thumbColor: thumbColor ?? this.thumbColor,
@ -181,7 +162,6 @@ class ScrollbarThemeData with Diagnosticable {
thumbVisibility: MaterialStateProperty.lerp<bool?>(a?.thumbVisibility, b?.thumbVisibility, t, _lerpBool), thumbVisibility: MaterialStateProperty.lerp<bool?>(a?.thumbVisibility, b?.thumbVisibility, t, _lerpBool),
thickness: MaterialStateProperty.lerp<double?>(a?.thickness, b?.thickness, t, lerpDouble), thickness: MaterialStateProperty.lerp<double?>(a?.thickness, b?.thickness, t, lerpDouble),
trackVisibility: MaterialStateProperty.lerp<bool?>(a?.trackVisibility, b?.trackVisibility, t, _lerpBool), trackVisibility: MaterialStateProperty.lerp<bool?>(a?.trackVisibility, b?.trackVisibility, t, _lerpBool),
showTrackOnHover: _lerpBool(a?.showTrackOnHover, b?.showTrackOnHover, t),
interactive: _lerpBool(a?.interactive, b?.interactive, t), interactive: _lerpBool(a?.interactive, b?.interactive, t),
radius: Radius.lerp(a?.radius, b?.radius, t), radius: Radius.lerp(a?.radius, b?.radius, t),
thumbColor: MaterialStateProperty.lerp<Color?>(a?.thumbColor, b?.thumbColor, t, Color.lerp), thumbColor: MaterialStateProperty.lerp<Color?>(a?.thumbColor, b?.thumbColor, t, Color.lerp),
@ -198,7 +178,6 @@ class ScrollbarThemeData with Diagnosticable {
thumbVisibility, thumbVisibility,
thickness, thickness,
trackVisibility, trackVisibility,
showTrackOnHover,
interactive, interactive,
radius, radius,
thumbColor, thumbColor,
@ -221,7 +200,6 @@ class ScrollbarThemeData with Diagnosticable {
&& other.thumbVisibility == thumbVisibility && other.thumbVisibility == thumbVisibility
&& other.thickness == thickness && other.thickness == thickness
&& other.trackVisibility == trackVisibility && other.trackVisibility == trackVisibility
&& other.showTrackOnHover == showTrackOnHover
&& other.interactive == interactive && other.interactive == interactive
&& other.radius == radius && other.radius == radius
&& other.thumbColor == thumbColor && other.thumbColor == thumbColor
@ -238,7 +216,6 @@ class ScrollbarThemeData with Diagnosticable {
properties.add(DiagnosticsProperty<MaterialStateProperty<bool?>>('thumbVisibility', thumbVisibility, defaultValue: null)); properties.add(DiagnosticsProperty<MaterialStateProperty<bool?>>('thumbVisibility', thumbVisibility, defaultValue: null));
properties.add(DiagnosticsProperty<MaterialStateProperty<double?>>('thickness', thickness, defaultValue: null)); properties.add(DiagnosticsProperty<MaterialStateProperty<double?>>('thickness', thickness, defaultValue: null));
properties.add(DiagnosticsProperty<MaterialStateProperty<bool?>>('trackVisibility', trackVisibility, defaultValue: null)); properties.add(DiagnosticsProperty<MaterialStateProperty<bool?>>('trackVisibility', trackVisibility, defaultValue: null));
properties.add(DiagnosticsProperty<bool>('showTrackOnHover', showTrackOnHover, defaultValue: null));
properties.add(DiagnosticsProperty<bool>('interactive', interactive, defaultValue: null)); properties.add(DiagnosticsProperty<bool>('interactive', interactive, defaultValue: null));
properties.add(DiagnosticsProperty<Radius>('radius', radius, defaultValue: null)); properties.add(DiagnosticsProperty<Radius>('radius', radius, defaultValue: null));
properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('thumbColor', thumbColor, defaultValue: null)); properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('thumbColor', thumbColor, defaultValue: null));

View file

@ -1020,7 +1020,12 @@ void main() {
useMaterial3: false, useMaterial3: false,
scrollbarTheme: ScrollbarThemeData( scrollbarTheme: ScrollbarThemeData(
thumbVisibility: MaterialStateProperty.all(true), thumbVisibility: MaterialStateProperty.all(true),
showTrackOnHover: true, trackVisibility: MaterialStateProperty.resolveWith((Set<MaterialState> states) {
if (states.contains(MaterialState.hovered)) {
return true;
}
return false;
})
), ),
), ),
home: const SingleChildScrollView( 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( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData( 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( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData( theme: ThemeData(
useMaterial3: false, useMaterial3: false,
scrollbarTheme: ScrollbarThemeData( scrollbarTheme: ScrollbarThemeData(
thumbVisibility: MaterialStateProperty.all(true), thumbVisibility: MaterialStateProperty.all(true),
showTrackOnHover: true, trackVisibility: MaterialStateProperty.resolveWith((Set<MaterialState> states) {
if (states.contains(MaterialState.hovered)) {
return true;
}
return false;
}),
), ),
), ),
home: const SingleChildScrollView( home: const SingleChildScrollView(

View file

@ -33,12 +33,21 @@ void main() {
final ScrollController scrollController = ScrollController(); final ScrollController scrollController = ScrollController();
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
theme: ThemeData(useMaterial3: false), theme: ThemeData(
useMaterial3: false,
scrollbarTheme: ScrollbarThemeData(
trackVisibility: MaterialStateProperty.resolveWith((Set<MaterialState> states) {
if (states.contains(MaterialState.hovered)) {
return true;
}
return false;
})
)
),
home: ScrollConfiguration( home: ScrollConfiguration(
behavior: const NoScrollbarBehavior(), behavior: const NoScrollbarBehavior(),
child: Scrollbar( child: Scrollbar(
thumbVisibility: true, thumbVisibility: true,
showTrackOnHover: true,
controller: scrollController, controller: scrollController,
child: SingleChildScrollView( child: SingleChildScrollView(
controller: scrollController, controller: scrollController,
@ -363,7 +372,6 @@ void main() {
testWidgets('Scrollbar widget properties take priority over theme', (WidgetTester tester) async { testWidgets('Scrollbar widget properties take priority over theme', (WidgetTester tester) async {
const double thickness = 4.0; const double thickness = 4.0;
const double edgeMargin = 2.0; const double edgeMargin = 2.0;
const bool showTrackOnHover = true;
const Radius radius = Radius.circular(3.0); const Radius radius = Radius.circular(3.0);
final ScrollController scrollController = ScrollController(); final ScrollController scrollController = ScrollController();
@ -371,13 +379,20 @@ void main() {
MaterialApp( MaterialApp(
theme: ThemeData( theme: ThemeData(
colorScheme: const ColorScheme.light(), colorScheme: const ColorScheme.light(),
scrollbarTheme: ScrollbarThemeData(
trackVisibility: MaterialStateProperty.resolveWith((Set<MaterialState> states) {
if (states.contains(MaterialState.hovered)) {
return true;
}
return false;
})
),
), ),
home: ScrollConfiguration( home: ScrollConfiguration(
behavior: const NoScrollbarBehavior(), behavior: const NoScrollbarBehavior(),
child: Scrollbar( child: Scrollbar(
thickness: thickness, thickness: thickness,
thumbVisibility: true, thumbVisibility: true,
showTrackOnHover: showTrackOnHover,
radius: radius, radius: radius,
controller: scrollController, controller: scrollController,
child: SingleChildScrollView( child: SingleChildScrollView(
@ -465,15 +480,24 @@ void main() {
testWidgets('ThemeData colorScheme is used when no ScrollbarTheme is set', (WidgetTester tester) async { testWidgets('ThemeData colorScheme is used when no ScrollbarTheme is set', (WidgetTester tester) async {
(ScrollController, Widget) buildFrame(ThemeData appTheme) { (ScrollController, Widget) buildFrame(ThemeData appTheme) {
final ScrollController scrollController = ScrollController(); final ScrollController scrollController = ScrollController();
final ThemeData theme = appTheme.copyWith(
scrollbarTheme: ScrollbarThemeData(
trackVisibility: MaterialStateProperty.resolveWith((Set<MaterialState> states) {
if (states.contains(MaterialState.hovered)) {
return true;
}
return false;
})
),
);
return ( return (
scrollController, scrollController,
MaterialApp( MaterialApp(
theme: appTheme, theme: theme,
home: ScrollConfiguration( home: ScrollConfiguration(
behavior: const NoScrollbarBehavior(), behavior: const NoScrollbarBehavior(),
child: Scrollbar( child: Scrollbar(
thumbVisibility: true, thumbVisibility: true,
showTrackOnHover: true,
controller: scrollController, controller: scrollController,
child: SingleChildScrollView( child: SingleChildScrollView(
controller: scrollController, controller: scrollController,
@ -654,7 +678,6 @@ void main() {
behavior: const NoScrollbarBehavior(), behavior: const NoScrollbarBehavior(),
child: Scrollbar( child: Scrollbar(
thumbVisibility: true, thumbVisibility: true,
showTrackOnHover: true,
controller: scrollController, controller: scrollController,
child: SingleChildScrollView( child: SingleChildScrollView(
controller: scrollController, controller: scrollController,
@ -702,7 +725,6 @@ void main() {
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
ScrollbarThemeData( ScrollbarThemeData(
thickness: MaterialStateProperty.resolveWith(_getThickness), thickness: MaterialStateProperty.resolveWith(_getThickness),
showTrackOnHover: true,
thumbVisibility: MaterialStateProperty.resolveWith(_getThumbVisibility), thumbVisibility: MaterialStateProperty.resolveWith(_getThumbVisibility),
radius: const Radius.circular(3.0), radius: const Radius.circular(3.0),
thumbColor: MaterialStateProperty.resolveWith(_getThumbColor), thumbColor: MaterialStateProperty.resolveWith(_getThumbColor),
@ -721,7 +743,6 @@ void main() {
expect(description, <String>[ expect(description, <String>[
"thumbVisibility: Instance of '_MaterialStatePropertyWith<bool?>'", "thumbVisibility: Instance of '_MaterialStatePropertyWith<bool?>'",
"thickness: Instance of '_MaterialStatePropertyWith<double?>'", "thickness: Instance of '_MaterialStatePropertyWith<double?>'",
'showTrackOnHover: true',
'radius: Radius.circular(3.0)', 'radius: Radius.circular(3.0)',
"thumbColor: Instance of '_MaterialStatePropertyWith<Color?>'", "thumbColor: Instance of '_MaterialStatePropertyWith<Color?>'",
"trackColor: Instance of '_MaterialStatePropertyWith<Color?>'", "trackColor: Instance of '_MaterialStatePropertyWith<Color?>'",
@ -749,7 +770,6 @@ class NoScrollbarBehavior extends ScrollBehavior {
ScrollbarThemeData _scrollbarTheme({ ScrollbarThemeData _scrollbarTheme({
MaterialStateProperty<double?>? thickness, MaterialStateProperty<double?>? thickness,
MaterialStateProperty<bool?>? trackVisibility, MaterialStateProperty<bool?>? trackVisibility,
bool showTrackOnHover = true,
MaterialStateProperty<bool?>? thumbVisibility, MaterialStateProperty<bool?>? thumbVisibility,
Radius radius = const Radius.circular(6.0), Radius radius = const Radius.circular(6.0),
MaterialStateProperty<Color?>? thumbColor, MaterialStateProperty<Color?>? thumbColor,
@ -761,8 +781,12 @@ ScrollbarThemeData _scrollbarTheme({
}) { }) {
return ScrollbarThemeData( return ScrollbarThemeData(
thickness: thickness ?? MaterialStateProperty.resolveWith(_getThickness), thickness: thickness ?? MaterialStateProperty.resolveWith(_getThickness),
trackVisibility: trackVisibility, trackVisibility: trackVisibility ?? MaterialStateProperty.resolveWith((Set<MaterialState> states) {
showTrackOnHover: showTrackOnHover, if (states.contains(MaterialState.hovered)) {
return true;
}
return false;
}),
thumbVisibility: thumbVisibility, thumbVisibility: thumbVisibility,
radius: radius, radius: radius,
thumbColor: thumbColor ?? MaterialStateProperty.resolveWith(_getThumbColor), thumbColor: thumbColor ?? MaterialStateProperty.resolveWith(_getThumbColor),