Skip to content

Commit ae736e2

Browse files
authored
Introduce Material 3 year2023 flag to SliderThemeData (#159721)
Related to [Introduce Material 3 `year2023` flag to the updated widget themes](flutter/flutter#159484) ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent d311b48 commit ae736e2

File tree

3 files changed

+300
-179
lines changed

3 files changed

+300
-179
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ class Slider extends StatefulWidget {
192192
'Use SliderTheme to customize the Slider appearance. '
193193
'This feature was deprecated after v3.27.0-0.1.pre.'
194194
)
195-
this.year2023 = true,
195+
this.year2023,
196196
}) : _sliderType = _SliderType.material,
197197
assert(min <= max),
198198
assert(value >= min && value <= max,
@@ -238,7 +238,7 @@ class Slider extends StatefulWidget {
238238
'Use SliderTheme to customize the Slider appearance. '
239239
'This feature was deprecated after v3.27.0-0.1.pre.'
240240
)
241-
this.year2023 = true,
241+
this.year2023,
242242
}) : _sliderType = _SliderType.adaptive,
243243
padding = null,
244244
assert(min <= max),
@@ -557,17 +557,18 @@ class Slider extends StatefulWidget {
557557
/// overlay shape, whichever is larger.
558558
final EdgeInsetsGeometry? padding;
559559

560-
/// When true, the [Slider] will use the 2023 Material 3 design appearance.
560+
/// When true, the [Slider] will use the 2023 Material Design 3 appearance.
561+
/// Defaults to true.
561562
///
562-
/// Defaults to true. If false, the [Slider] will use the latest Material 3
563-
/// Design appearance, which was introduced in December 2023.
563+
/// If this is set to false, the [Slider] will use the latest Material Design 3
564+
/// appearance, which was introduced in December 2023.
564565
///
565566
/// If [ThemeData.useMaterial3] is false, then this property is ignored.
566567
@Deprecated(
567568
'Use SliderTheme to customize the Slider appearance. '
568569
'This feature was deprecated after v3.27.0-0.1.pre.'
569570
)
570-
final bool year2023;
571+
final bool? year2023;
571572

572573
final _SliderType _sliderType ;
573574

@@ -801,8 +802,9 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin {
801802
Widget _buildMaterialSlider(BuildContext context) {
802803
final ThemeData theme = Theme.of(context);
803804
SliderThemeData sliderTheme = SliderTheme.of(context);
805+
final bool year2023 = widget.year2023 ?? sliderTheme.year2023 ?? true;
804806
final SliderThemeData defaults = switch (theme.useMaterial3) {
805-
true => widget.year2023
807+
true => year2023
806808
? _SliderDefaultsM3Year2023(context)
807809
: _SliderDefaultsM3(context),
808810
false => _SliderDefaultsM2(context),

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,11 @@ class SliderThemeData with Diagnosticable {
299299
this.padding,
300300
this.thumbSize,
301301
this.trackGap,
302+
@Deprecated(
303+
'Use SliderTheme to customize the Slider appearance. '
304+
'This feature was deprecated after v3.27.0-0.2.pre.'
305+
)
306+
this.year2023,
302307
});
303308

304309
/// Generates a SliderThemeData from three main colors.
@@ -623,6 +628,21 @@ class SliderThemeData with Diagnosticable {
623628
/// Defaults to 6.0 pixels of gap between the active and inactive tracks.
624629
final double? trackGap;
625630

631+
/// Overrides the default value of [Slider.year2023].
632+
///
633+
/// When true, the [Slider] will use the 2023 Material Design 3 appearance.
634+
/// Defaults to true.
635+
///
636+
/// If this is set to false, the [Slider] will use the latest Material Design 3
637+
/// appearance, which was introduced in December 2023.
638+
///
639+
/// If [ThemeData.useMaterial3] is false, then this property is ignored.
640+
@Deprecated(
641+
'Use SliderTheme to customize the Slider appearance. '
642+
'This feature was deprecated after v3.27.0-0.2.pre.'
643+
)
644+
final bool? year2023;
645+
626646
/// Creates a copy of this object but with the given fields replaced with the
627647
/// new values.
628648
SliderThemeData copyWith({
@@ -661,6 +681,7 @@ class SliderThemeData with Diagnosticable {
661681
EdgeInsetsGeometry? padding,
662682
MaterialStateProperty<Size?>? thumbSize,
663683
double? trackGap,
684+
bool? year2023,
664685
}) {
665686
return SliderThemeData(
666687
trackHeight: trackHeight ?? this.trackHeight,
@@ -698,6 +719,7 @@ class SliderThemeData with Diagnosticable {
698719
padding: padding ?? this.padding,
699720
thumbSize: thumbSize ?? this.thumbSize,
700721
trackGap: trackGap ?? this.trackGap,
722+
year2023: year2023 ?? this.year2023,
701723
);
702724
}
703725

@@ -744,6 +766,7 @@ class SliderThemeData with Diagnosticable {
744766
padding: EdgeInsetsGeometry.lerp(a.padding, b.padding, t),
745767
thumbSize: MaterialStateProperty.lerp<Size?>(a.thumbSize, b.thumbSize, t, Size.lerp),
746768
trackGap: lerpDouble(a.trackGap, b.trackGap, t),
769+
year2023: t < 0.5 ? a.year2023 : b.year2023,
747770
);
748771
}
749772

@@ -784,6 +807,7 @@ class SliderThemeData with Diagnosticable {
784807
padding,
785808
thumbSize,
786809
trackGap,
810+
year2023,
787811
),
788812
);
789813

@@ -830,7 +854,8 @@ class SliderThemeData with Diagnosticable {
830854
&& other.allowedInteraction == allowedInteraction
831855
&& other.padding == padding
832856
&& other.thumbSize == thumbSize
833-
&& other.trackGap == trackGap;
857+
&& other.trackGap == trackGap
858+
&& other.year2023 == year2023;
834859
}
835860

836861
@override
@@ -872,6 +897,7 @@ class SliderThemeData with Diagnosticable {
872897
properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('padding', padding, defaultValue: defaultData.padding));
873898
properties.add(DiagnosticsProperty<MaterialStateProperty<Size?>>('thumbSize', thumbSize, defaultValue: defaultData.thumbSize));
874899
properties.add(DoubleProperty('trackGap', trackGap, defaultValue: defaultData.trackGap));
900+
properties.add(DiagnosticsProperty<bool>('year2023', year2023, defaultValue: defaultData.year2023));
875901
}
876902
}
877903

0 commit comments

Comments
 (0)