Skip to content

Commit

Permalink
Remove showTrackOnHover from Scrollbar and ScrollbarTheme (#144180
Browse files Browse the repository at this point in the history
)

This PR is to remove deprecated `Scrollbar.showTrackOnHover` and `ScrollbarThemeData.showTrackOnHover`.

These parameters are made obsolete in #111706.
Part of #143956
  • Loading branch information
QuncCccccc committed Mar 13, 2024
1 parent 59da4de commit 1ccad1a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 70 deletions.
29 changes: 0 additions & 29 deletions packages/flutter/lib/src/material/scrollbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -190,7 +169,6 @@ class Scrollbar extends StatelessWidget {
controller: controller,
thumbVisibility: thumbVisibility,
trackVisibility: trackVisibility,
showTrackOnHover: showTrackOnHover,
thickness: thickness,
radius: radius,
notificationPredicate: notificationPredicate,
Expand All @@ -207,7 +185,6 @@ class _MaterialScrollbar extends RawScrollbar {
super.controller,
super.thumbVisibility,
super.trackVisibility,
this.showTrackOnHover,
super.thickness,
super.radius,
ScrollNotificationPredicate? notificationPredicate,
Expand All @@ -220,8 +197,6 @@ class _MaterialScrollbar extends RawScrollbar {
notificationPredicate: notificationPredicate ?? defaultScrollNotificationPredicate,
);

final bool? showTrackOnHover;

@override
_MaterialScrollbarState createState() => _MaterialScrollbarState();
}
Expand All @@ -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<bool> get _trackVisibility => MaterialStateProperty.resolveWith((Set<MaterialState> states) {
if (states.contains(MaterialState.hovered) && _showTrackOnHover) {
return true;
}
return widget.trackVisibility ?? _scrollbarTheme.trackVisibility?.resolve(states) ?? false;
});

Expand Down
27 changes: 2 additions & 25 deletions packages/flutter/lib/src/material/scrollbar_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -67,14 +62,6 @@ class ScrollbarThemeData with Diagnosticable {
/// descendant [Scrollbar] widgets.
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
/// descendant [Scrollbar] widgets.
final bool? interactive;
Expand All @@ -92,14 +79,14 @@ class ScrollbarThemeData with Diagnosticable {
final MaterialStateProperty<Color?>? 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<Color?>? 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.
Expand Down Expand Up @@ -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,
Expand All @@ -181,7 +162,6 @@ class ScrollbarThemeData with Diagnosticable {
thumbVisibility: MaterialStateProperty.lerp<bool?>(a?.thumbVisibility, b?.thumbVisibility, t, _lerpBool),
thickness: MaterialStateProperty.lerp<double?>(a?.thickness, b?.thickness, t, lerpDouble),
trackVisibility: MaterialStateProperty.lerp<bool?>(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<Color?>(a?.thumbColor, b?.thumbColor, t, Color.lerp),
Expand All @@ -198,7 +178,6 @@ class ScrollbarThemeData with Diagnosticable {
thumbVisibility,
thickness,
trackVisibility,
showTrackOnHover,
interactive,
radius,
thumbColor,
Expand All @@ -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
Expand All @@ -238,7 +216,6 @@ class ScrollbarThemeData with Diagnosticable {
properties.add(DiagnosticsProperty<MaterialStateProperty<bool?>>('thumbVisibility', thumbVisibility, defaultValue: null));
properties.add(DiagnosticsProperty<MaterialStateProperty<double?>>('thickness', thickness, 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<Radius>('radius', radius, defaultValue: null));
properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('thumbColor', thumbColor, defaultValue: null));
Expand Down
18 changes: 14 additions & 4 deletions packages/flutter/test/material/scrollbar_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,12 @@ void main() {
useMaterial3: false,
scrollbarTheme: ScrollbarThemeData(
thumbVisibility: MaterialStateProperty.all(true),
showTrackOnHover: true,
trackVisibility: MaterialStateProperty.resolveWith((Set<MaterialState> states) {
if (states.contains(MaterialState.hovered)) {
return true;
}
return false;
})
),
),
home: const SingleChildScrollView(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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<MaterialState> states) {
if (states.contains(MaterialState.hovered)) {
return true;
}
return false;
}),
),
),
home: const SingleChildScrollView(
Expand Down
48 changes: 36 additions & 12 deletions packages/flutter/test/material/scrollbar_theme_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<MaterialState> 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,
Expand Down Expand Up @@ -363,21 +372,27 @@ 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();

await tester.pumpWidget(
MaterialApp(
theme: ThemeData(
colorScheme: const ColorScheme.light(),
scrollbarTheme: ScrollbarThemeData(
trackVisibility: MaterialStateProperty.resolveWith((Set<MaterialState> 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(
Expand Down Expand Up @@ -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<MaterialState> 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,
Expand Down Expand Up @@ -654,7 +678,6 @@ void main() {
behavior: const NoScrollbarBehavior(),
child: Scrollbar(
thumbVisibility: true,
showTrackOnHover: true,
controller: scrollController,
child: SingleChildScrollView(
controller: scrollController,
Expand Down Expand Up @@ -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),
Expand All @@ -721,7 +743,6 @@ void main() {
expect(description, <String>[
"thumbVisibility: Instance of '_MaterialStatePropertyWith<bool?>'",
"thickness: Instance of '_MaterialStatePropertyWith<double?>'",
'showTrackOnHover: true',
'radius: Radius.circular(3.0)',
"thumbColor: Instance of '_MaterialStatePropertyWith<Color?>'",
"trackColor: Instance of '_MaterialStatePropertyWith<Color?>'",
Expand Down Expand Up @@ -749,7 +770,6 @@ class NoScrollbarBehavior extends ScrollBehavior {
ScrollbarThemeData _scrollbarTheme({
MaterialStateProperty<double?>? thickness,
MaterialStateProperty<bool?>? trackVisibility,
bool showTrackOnHover = true,
MaterialStateProperty<bool?>? thumbVisibility,
Radius radius = const Radius.circular(6.0),
MaterialStateProperty<Color?>? thumbColor,
Expand All @@ -761,8 +781,12 @@ ScrollbarThemeData _scrollbarTheme({
}) {
return ScrollbarThemeData(
thickness: thickness ?? MaterialStateProperty.resolveWith(_getThickness),
trackVisibility: trackVisibility,
showTrackOnHover: showTrackOnHover,
trackVisibility: trackVisibility ?? MaterialStateProperty.resolveWith((Set<MaterialState> states) {
if (states.contains(MaterialState.hovered)) {
return true;
}
return false;
}),
thumbVisibility: thumbVisibility,
radius: radius,
thumbColor: thumbColor ?? MaterialStateProperty.resolveWith(_getThumbColor),
Expand Down

0 comments on commit 1ccad1a

Please sign in to comment.