Skip to content

Commit 1ccad1a

Browse files
authored
Remove showTrackOnHover from Scrollbar and ScrollbarTheme (#144180)
This PR is to remove deprecated `Scrollbar.showTrackOnHover` and `ScrollbarThemeData.showTrackOnHover`. These parameters are made obsolete in flutter/flutter#111706. Part of flutter/flutter#143956
1 parent 59da4de commit 1ccad1a

File tree

4 files changed

+52
-70
lines changed

4 files changed

+52
-70
lines changed

packages/flutter/lib/src/material/scrollbar.dart

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,6 @@ class Scrollbar extends StatelessWidget {
9595
this.notificationPredicate,
9696
this.interactive,
9797
this.scrollbarOrientation,
98-
@Deprecated(
99-
'Use ScrollbarThemeData.trackVisibility to resolve based on the current state instead. '
100-
'This feature was deprecated after v3.4.0-19.0.pre.',
101-
)
102-
this.showTrackOnHover,
10398
});
10499

105100
/// {@macro flutter.widgets.Scrollbar.child}
@@ -128,24 +123,8 @@ class Scrollbar extends StatelessWidget {
128123
/// If the track visibility is related to the scrollbar's material state,
129124
/// use the global [ScrollbarThemeData.trackVisibility] or override the
130125
/// sub-tree's theme data.
131-
///
132-
/// Replaces deprecated [showTrackOnHover].
133126
final bool? trackVisibility;
134127

135-
/// Controls if the track will show on hover and remain, including during drag.
136-
///
137-
/// If this property is null, then [ScrollbarThemeData.showTrackOnHover] of
138-
/// [ThemeData.scrollbarTheme] is used. If that is also null, the default value
139-
/// is false.
140-
///
141-
/// This is deprecated, [trackVisibility] or [ScrollbarThemeData.trackVisibility]
142-
/// should be used instead.
143-
@Deprecated(
144-
'Use ScrollbarThemeData.trackVisibility to resolve based on the current state instead. '
145-
'This feature was deprecated after v3.4.0-19.0.pre.',
146-
)
147-
final bool? showTrackOnHover;
148-
149128
/// The thickness of the scrollbar in the cross axis of the scrollable.
150129
///
151130
/// If null, the default value is platform dependent. On [TargetPlatform.android],
@@ -190,7 +169,6 @@ class Scrollbar extends StatelessWidget {
190169
controller: controller,
191170
thumbVisibility: thumbVisibility,
192171
trackVisibility: trackVisibility,
193-
showTrackOnHover: showTrackOnHover,
194172
thickness: thickness,
195173
radius: radius,
196174
notificationPredicate: notificationPredicate,
@@ -207,7 +185,6 @@ class _MaterialScrollbar extends RawScrollbar {
207185
super.controller,
208186
super.thumbVisibility,
209187
super.trackVisibility,
210-
this.showTrackOnHover,
211188
super.thickness,
212189
super.radius,
213190
ScrollNotificationPredicate? notificationPredicate,
@@ -220,8 +197,6 @@ class _MaterialScrollbar extends RawScrollbar {
220197
notificationPredicate: notificationPredicate ?? defaultScrollNotificationPredicate,
221198
);
222199

223-
final bool? showTrackOnHover;
224-
225200
@override
226201
_MaterialScrollbarState createState() => _MaterialScrollbarState();
227202
}
@@ -241,12 +216,8 @@ class _MaterialScrollbarState extends RawScrollbarState<_MaterialScrollbar> {
241216
@override
242217
bool get enableGestures => widget.interactive ?? _scrollbarTheme.interactive ?? !_useAndroidScrollbar;
243218

244-
bool get _showTrackOnHover => widget.showTrackOnHover ?? _scrollbarTheme.showTrackOnHover ?? false;
245219

246220
MaterialStateProperty<bool> get _trackVisibility => MaterialStateProperty.resolveWith((Set<MaterialState> states) {
247-
if (states.contains(MaterialState.hovered) && _showTrackOnHover) {
248-
return true;
249-
}
250221
return widget.trackVisibility ?? _scrollbarTheme.trackVisibility?.resolve(states) ?? false;
251222
});
252223

packages/flutter/lib/src/material/scrollbar_theme.dart

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ class ScrollbarThemeData with Diagnosticable {
4545
this.mainAxisMargin,
4646
this.minThumbLength,
4747
this.interactive,
48-
@Deprecated(
49-
'Use ScrollbarThemeData.trackVisibility to resolve based on the current state instead. '
50-
'This feature was deprecated after v3.4.0-19.0.pre.',
51-
)
52-
this.showTrackOnHover,
5348
});
5449

5550
/// Overrides the default value of [Scrollbar.thumbVisibility] in all
@@ -67,14 +62,6 @@ class ScrollbarThemeData with Diagnosticable {
6762
/// descendant [Scrollbar] widgets.
6863
final MaterialStateProperty<bool?>? trackVisibility;
6964

70-
/// Overrides the default value of [Scrollbar.showTrackOnHover] in all
71-
/// descendant [Scrollbar] widgets.
72-
@Deprecated(
73-
'Use ScrollbarThemeData.trackVisibility to resolve based on the current state instead. '
74-
'This feature was deprecated after v3.4.0-19.0.pre.',
75-
)
76-
final bool? showTrackOnHover;
77-
7865
/// Overrides the default value of [Scrollbar.interactive] in all
7966
/// descendant [Scrollbar] widgets.
8067
final bool? interactive;
@@ -92,14 +79,14 @@ class ScrollbarThemeData with Diagnosticable {
9279
final MaterialStateProperty<Color?>? thumbColor;
9380

9481
/// Overrides the default [Color] of the [Scrollbar] track when
95-
/// [showTrackOnHover] is true in all descendant [Scrollbar] widgets.
82+
/// [trackVisibility] is true in all descendant [Scrollbar] widgets.
9683
///
9784
/// Resolves in the following states:
9885
/// * [MaterialState.hovered] on web and desktop platforms.
9986
final MaterialStateProperty<Color?>? trackColor;
10087

10188
/// Overrides the default [Color] of the [Scrollbar] track border when
102-
/// [showTrackOnHover] is true in all descendant [Scrollbar] widgets.
89+
/// [trackVisibility] is true in all descendant [Scrollbar] widgets.
10390
///
10491
/// Resolves in the following states:
10592
/// * [MaterialState.hovered] on web and desktop platforms.
@@ -148,17 +135,11 @@ class ScrollbarThemeData with Diagnosticable {
148135
double? crossAxisMargin,
149136
double? mainAxisMargin,
150137
double? minThumbLength,
151-
@Deprecated(
152-
'Use ScrollbarThemeData.trackVisibility to resolve based on the current state instead. '
153-
'This feature was deprecated after v3.4.0-19.0.pre.',
154-
)
155-
bool? showTrackOnHover,
156138
}) {
157139
return ScrollbarThemeData(
158140
thumbVisibility: thumbVisibility ?? this.thumbVisibility,
159141
thickness: thickness ?? this.thickness,
160142
trackVisibility: trackVisibility ?? this.trackVisibility,
161-
showTrackOnHover: showTrackOnHover ?? this.showTrackOnHover,
162143
interactive: interactive ?? this.interactive,
163144
radius: radius ?? this.radius,
164145
thumbColor: thumbColor ?? this.thumbColor,
@@ -181,7 +162,6 @@ class ScrollbarThemeData with Diagnosticable {
181162
thumbVisibility: MaterialStateProperty.lerp<bool?>(a?.thumbVisibility, b?.thumbVisibility, t, _lerpBool),
182163
thickness: MaterialStateProperty.lerp<double?>(a?.thickness, b?.thickness, t, lerpDouble),
183164
trackVisibility: MaterialStateProperty.lerp<bool?>(a?.trackVisibility, b?.trackVisibility, t, _lerpBool),
184-
showTrackOnHover: _lerpBool(a?.showTrackOnHover, b?.showTrackOnHover, t),
185165
interactive: _lerpBool(a?.interactive, b?.interactive, t),
186166
radius: Radius.lerp(a?.radius, b?.radius, t),
187167
thumbColor: MaterialStateProperty.lerp<Color?>(a?.thumbColor, b?.thumbColor, t, Color.lerp),
@@ -198,7 +178,6 @@ class ScrollbarThemeData with Diagnosticable {
198178
thumbVisibility,
199179
thickness,
200180
trackVisibility,
201-
showTrackOnHover,
202181
interactive,
203182
radius,
204183
thumbColor,
@@ -221,7 +200,6 @@ class ScrollbarThemeData with Diagnosticable {
221200
&& other.thumbVisibility == thumbVisibility
222201
&& other.thickness == thickness
223202
&& other.trackVisibility == trackVisibility
224-
&& other.showTrackOnHover == showTrackOnHover
225203
&& other.interactive == interactive
226204
&& other.radius == radius
227205
&& other.thumbColor == thumbColor
@@ -238,7 +216,6 @@ class ScrollbarThemeData with Diagnosticable {
238216
properties.add(DiagnosticsProperty<MaterialStateProperty<bool?>>('thumbVisibility', thumbVisibility, defaultValue: null));
239217
properties.add(DiagnosticsProperty<MaterialStateProperty<double?>>('thickness', thickness, defaultValue: null));
240218
properties.add(DiagnosticsProperty<MaterialStateProperty<bool?>>('trackVisibility', trackVisibility, defaultValue: null));
241-
properties.add(DiagnosticsProperty<bool>('showTrackOnHover', showTrackOnHover, defaultValue: null));
242219
properties.add(DiagnosticsProperty<bool>('interactive', interactive, defaultValue: null));
243220
properties.add(DiagnosticsProperty<Radius>('radius', radius, defaultValue: null));
244221
properties.add(DiagnosticsProperty<MaterialStateProperty<Color?>>('thumbColor', thumbColor, defaultValue: null));

packages/flutter/test/material/scrollbar_test.dart

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,12 @@ void main() {
10201020
useMaterial3: false,
10211021
scrollbarTheme: ScrollbarThemeData(
10221022
thumbVisibility: MaterialStateProperty.all(true),
1023-
showTrackOnHover: true,
1023+
trackVisibility: MaterialStateProperty.resolveWith((Set<MaterialState> states) {
1024+
if (states.contains(MaterialState.hovered)) {
1025+
return true;
1026+
}
1027+
return false;
1028+
})
10241029
),
10251030
),
10261031
home: const SingleChildScrollView(
@@ -1160,7 +1165,7 @@ void main() {
11601165
}),
11611166
);
11621167

1163-
testWidgets('ScrollbarThemeData.trackVisibility replaces showTrackOnHover', (WidgetTester tester) async {
1168+
testWidgets('ScrollbarThemeData.trackVisibility', (WidgetTester tester) async {
11641169
await tester.pumpWidget(
11651170
MaterialApp(
11661171
theme: ThemeData(
@@ -1228,14 +1233,19 @@ void main() {
12281233
}),
12291234
);
12301235

1231-
testWidgets('Scrollbar showTrackOnHover', (WidgetTester tester) async {
1236+
testWidgets('Scrollbar trackVisibility on hovered', (WidgetTester tester) async {
12321237
await tester.pumpWidget(
12331238
MaterialApp(
12341239
theme: ThemeData(
12351240
useMaterial3: false,
12361241
scrollbarTheme: ScrollbarThemeData(
12371242
thumbVisibility: MaterialStateProperty.all(true),
1238-
showTrackOnHover: true,
1243+
trackVisibility: MaterialStateProperty.resolveWith((Set<MaterialState> states) {
1244+
if (states.contains(MaterialState.hovered)) {
1245+
return true;
1246+
}
1247+
return false;
1248+
}),
12391249
),
12401250
),
12411251
home: const SingleChildScrollView(

packages/flutter/test/material/scrollbar_theme_test.dart

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,21 @@ void main() {
3333
final ScrollController scrollController = ScrollController();
3434
await tester.pumpWidget(
3535
MaterialApp(
36-
theme: ThemeData(useMaterial3: false),
36+
theme: ThemeData(
37+
useMaterial3: false,
38+
scrollbarTheme: ScrollbarThemeData(
39+
trackVisibility: MaterialStateProperty.resolveWith((Set<MaterialState> states) {
40+
if (states.contains(MaterialState.hovered)) {
41+
return true;
42+
}
43+
return false;
44+
})
45+
)
46+
),
3747
home: ScrollConfiguration(
3848
behavior: const NoScrollbarBehavior(),
3949
child: Scrollbar(
4050
thumbVisibility: true,
41-
showTrackOnHover: true,
4251
controller: scrollController,
4352
child: SingleChildScrollView(
4453
controller: scrollController,
@@ -363,21 +372,27 @@ void main() {
363372
testWidgets('Scrollbar widget properties take priority over theme', (WidgetTester tester) async {
364373
const double thickness = 4.0;
365374
const double edgeMargin = 2.0;
366-
const bool showTrackOnHover = true;
367375
const Radius radius = Radius.circular(3.0);
368376
final ScrollController scrollController = ScrollController();
369377

370378
await tester.pumpWidget(
371379
MaterialApp(
372380
theme: ThemeData(
373381
colorScheme: const ColorScheme.light(),
382+
scrollbarTheme: ScrollbarThemeData(
383+
trackVisibility: MaterialStateProperty.resolveWith((Set<MaterialState> states) {
384+
if (states.contains(MaterialState.hovered)) {
385+
return true;
386+
}
387+
return false;
388+
})
389+
),
374390
),
375391
home: ScrollConfiguration(
376392
behavior: const NoScrollbarBehavior(),
377393
child: Scrollbar(
378394
thickness: thickness,
379395
thumbVisibility: true,
380-
showTrackOnHover: showTrackOnHover,
381396
radius: radius,
382397
controller: scrollController,
383398
child: SingleChildScrollView(
@@ -465,15 +480,24 @@ void main() {
465480
testWidgets('ThemeData colorScheme is used when no ScrollbarTheme is set', (WidgetTester tester) async {
466481
(ScrollController, Widget) buildFrame(ThemeData appTheme) {
467482
final ScrollController scrollController = ScrollController();
483+
final ThemeData theme = appTheme.copyWith(
484+
scrollbarTheme: ScrollbarThemeData(
485+
trackVisibility: MaterialStateProperty.resolveWith((Set<MaterialState> states) {
486+
if (states.contains(MaterialState.hovered)) {
487+
return true;
488+
}
489+
return false;
490+
})
491+
),
492+
);
468493
return (
469494
scrollController,
470495
MaterialApp(
471-
theme: appTheme,
496+
theme: theme,
472497
home: ScrollConfiguration(
473498
behavior: const NoScrollbarBehavior(),
474499
child: Scrollbar(
475500
thumbVisibility: true,
476-
showTrackOnHover: true,
477501
controller: scrollController,
478502
child: SingleChildScrollView(
479503
controller: scrollController,
@@ -654,7 +678,6 @@ void main() {
654678
behavior: const NoScrollbarBehavior(),
655679
child: Scrollbar(
656680
thumbVisibility: true,
657-
showTrackOnHover: true,
658681
controller: scrollController,
659682
child: SingleChildScrollView(
660683
controller: scrollController,
@@ -702,7 +725,6 @@ void main() {
702725
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
703726
ScrollbarThemeData(
704727
thickness: MaterialStateProperty.resolveWith(_getThickness),
705-
showTrackOnHover: true,
706728
thumbVisibility: MaterialStateProperty.resolveWith(_getThumbVisibility),
707729
radius: const Radius.circular(3.0),
708730
thumbColor: MaterialStateProperty.resolveWith(_getThumbColor),
@@ -721,7 +743,6 @@ void main() {
721743
expect(description, <String>[
722744
"thumbVisibility: Instance of '_MaterialStatePropertyWith<bool?>'",
723745
"thickness: Instance of '_MaterialStatePropertyWith<double?>'",
724-
'showTrackOnHover: true',
725746
'radius: Radius.circular(3.0)',
726747
"thumbColor: Instance of '_MaterialStatePropertyWith<Color?>'",
727748
"trackColor: Instance of '_MaterialStatePropertyWith<Color?>'",
@@ -749,7 +770,6 @@ class NoScrollbarBehavior extends ScrollBehavior {
749770
ScrollbarThemeData _scrollbarTheme({
750771
MaterialStateProperty<double?>? thickness,
751772
MaterialStateProperty<bool?>? trackVisibility,
752-
bool showTrackOnHover = true,
753773
MaterialStateProperty<bool?>? thumbVisibility,
754774
Radius radius = const Radius.circular(6.0),
755775
MaterialStateProperty<Color?>? thumbColor,
@@ -761,8 +781,12 @@ ScrollbarThemeData _scrollbarTheme({
761781
}) {
762782
return ScrollbarThemeData(
763783
thickness: thickness ?? MaterialStateProperty.resolveWith(_getThickness),
764-
trackVisibility: trackVisibility,
765-
showTrackOnHover: showTrackOnHover,
784+
trackVisibility: trackVisibility ?? MaterialStateProperty.resolveWith((Set<MaterialState> states) {
785+
if (states.contains(MaterialState.hovered)) {
786+
return true;
787+
}
788+
return false;
789+
}),
766790
thumbVisibility: thumbVisibility,
767791
radius: radius,
768792
thumbColor: thumbColor ?? MaterialStateProperty.resolveWith(_getThumbColor),

0 commit comments

Comments
 (0)