Skip to content

Commit 56cfef7

Browse files
authored
Introduce new Material 3 Slider shapes (#152237)
fixes [Update `Slider` for Material 3 redesign](flutter/flutter#141842) previous implementation flutter/flutter#147783 ### Description This PR introduces new Material 3 Slider design. ### Slider Preview <img width="912" alt="Screenshot 2024-07-24 at 16 38 11" src="https://github.com/user-attachments/assets/9645ff6c-b72a-40aa-ae95-4f76994f8302"> <img width="912" alt="Screenshot 2024-07-24 at 16 38 24" src="https://github.com/user-attachments/assets/fbaed8bb-2717-43a9-9415-ea1365165d9a"> ### Value indicator Preview https://github.com/user-attachments/assets/45fa001c-de81-433a-a8e9-6c0d6a2335c0 ### New stop indicator https://github.com/user-attachments/assets/ad05621d-042d-4b17-9dbb-7f7b802a2593 ### Customized <img width="912" alt="Screenshot 2024-07-24 at 16 41 49" src="https://github.com/user-attachments/assets/2f279240-5af8-4bc8-9c65-a4b4ac718101"> ## 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 8536b96 commit 56cfef7

File tree

7 files changed

+1170
-51
lines changed

7 files changed

+1170
-51
lines changed

dev/tools/gen_defaults/bin/gen_defaults.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import 'package:gen_defaults/radio_template.dart';
4747
import 'package:gen_defaults/search_bar_template.dart';
4848
import 'package:gen_defaults/search_view_template.dart';
4949
import 'package:gen_defaults/segmented_button_template.dart';
50+
import 'package:gen_defaults/slider_template.dart';
5051
import 'package:gen_defaults/snackbar_template.dart';
5152
import 'package:gen_defaults/surface_tint.dart';
5253
import 'package:gen_defaults/switch_template.dart';
@@ -142,8 +143,7 @@ Future<void> main(List<String> args) async {
142143
SearchViewTemplate('SearchView', '$materialLib/search_anchor.dart', tokens).updateFile();
143144
SegmentedButtonTemplate('md.comp.outlined-segmented-button', 'SegmentedButton', '$materialLib/segmented_button.dart', tokens).updateFile();
144145
SnackbarTemplate('md.comp.snackbar', 'Snackbar', '$materialLib/snack_bar.dart', tokens).updateFile();
145-
// TODO(QuncCccccc): uncomment `SliderTemplate` once `Slider` widget is updated to match the latest M3 specs.
146-
// SliderTemplate('md.comp.slider', 'Slider', '$materialLib/slider.dart', tokens).updateFile();
146+
SliderTemplate('md.comp.slider', 'Slider', '$materialLib/slider.dart', tokens).updateFile();
147147
SurfaceTintTemplate('SurfaceTint', '$materialLib/elevation_overlay.dart', tokens).updateFile();
148148
SwitchTemplate('Switch', '$materialLib/switch.dart', tokens).updateFile();
149149
TimePickerTemplate('TimePicker', '$materialLib/time_picker.dart', tokens).updateFile();

dev/tools/gen_defaults/generated/used_tokens.csv

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,33 @@ md.comp.sheet.bottom.docked.drag-handle.height,
655655
md.comp.sheet.bottom.docked.drag-handle.width,
656656
md.comp.sheet.bottom.docked.modal.container.elevation,
657657
md.comp.sheet.bottom.docked.standard.container.elevation,
658+
md.comp.slider.active.handle.padding,
659+
md.comp.slider.active.stop-indicator.container.color,
660+
md.comp.slider.active.stop-indicator.container.opacity,
661+
md.comp.slider.active.track.color,
662+
md.comp.slider.active.track.height,
663+
md.comp.slider.disabled.active.stop-indicator.container.color,
664+
md.comp.slider.disabled.active.track.color,
665+
md.comp.slider.disabled.active.track.opacity,
666+
md.comp.slider.disabled.handle.color,
667+
md.comp.slider.disabled.handle.opacity,
668+
md.comp.slider.disabled.handle.width,
669+
md.comp.slider.disabled.inactive.stop-indicator.container.color,
670+
md.comp.slider.disabled.inactive.track.color,
671+
md.comp.slider.disabled.inactive.track.opacity,
672+
md.comp.slider.focus.handle.width,
673+
md.comp.slider.handle.color,
674+
md.comp.slider.handle.height,
675+
md.comp.slider.handle.width,
676+
md.comp.slider.hover.handle.width,
677+
md.comp.slider.inactive.stop-indicator.container.color,
678+
md.comp.slider.inactive.stop-indicator.container.opacity,
679+
md.comp.slider.inactive.track.color,
680+
md.comp.slider.pressed.handle.width,
681+
md.comp.slider.stop-indicator.size,
682+
md.comp.slider.value-indicator.container.color,
683+
md.comp.slider.value-indicator.label.label-text.color,
684+
md.comp.slider.value-indicator.label.label-text.text-style,
658685
md.comp.snackbar.action.focus.label-text.color,
659686
md.comp.snackbar.action.hover.label-text.color,
660687
md.comp.snackbar.action.label-text.color,

dev/tools/gen_defaults/lib/slider_template.dart

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class _${blockName}DefaultsM3 extends SliderThemeData {
2727
Color? get inactiveTrackColor => ${componentColor('$tokenGroup.inactive.track')};
2828
2929
@override
30-
Color? get secondaryActiveTrackColor => _colors.primary.withOpacity(0.54);
30+
Color? get secondaryActiveTrackColor => ${componentColor('$tokenGroup.active.track')}.withOpacity(0.54);
3131
3232
@override
3333
Color? get disabledActiveTrackColor => ${componentColor('$tokenGroup.disabled.active.track')};
@@ -36,49 +36,85 @@ class _${blockName}DefaultsM3 extends SliderThemeData {
3636
Color? get disabledInactiveTrackColor => ${componentColor('$tokenGroup.disabled.inactive.track')};
3737
3838
@override
39-
Color? get disabledSecondaryActiveTrackColor => _colors.onSurface.withOpacity(0.12);
39+
Color? get disabledSecondaryActiveTrackColor => ${componentColor('$tokenGroup.disabled.active.track')};
4040
4141
@override
42-
Color? get activeTickMarkColor => ${componentColor('$tokenGroup.with-tick-marks.active.container')};
42+
Color? get activeTickMarkColor => ${componentColor('$tokenGroup.active.stop-indicator.container')};
4343
4444
@override
45-
Color? get inactiveTickMarkColor => ${componentColor('$tokenGroup.with-tick-marks.inactive.container')};
45+
Color? get inactiveTickMarkColor => ${componentColor('$tokenGroup.inactive.stop-indicator.container')};
4646
4747
@override
48-
Color? get disabledActiveTickMarkColor => ${componentColor('$tokenGroup.with-tick-marks.disabled.container')};
48+
Color? get disabledActiveTickMarkColor => ${componentColor('$tokenGroup.disabled.active.stop-indicator.container')};
4949
5050
@override
51-
Color? get disabledInactiveTickMarkColor => ${componentColor('$tokenGroup.with-tick-marks.disabled.container')};
51+
Color? get disabledInactiveTickMarkColor => ${componentColor('$tokenGroup.disabled.inactive.stop-indicator.container')};
5252
5353
@override
5454
Color? get thumbColor => ${componentColor('$tokenGroup.handle')};
5555
5656
@override
57-
Color? get disabledThumbColor => Color.alphaBlend(${componentColor('$tokenGroup.disabled.handle')}, _colors.surface);
57+
Color? get disabledThumbColor => ${componentColor('$tokenGroup.disabled.handle')};
5858
5959
@override
6060
Color? get overlayColor => MaterialStateColor.resolveWith((Set<MaterialState> states) {
6161
if (states.contains(MaterialState.dragged)) {
62-
return ${componentColor('$tokenGroup.pressed.state-layer')};
62+
return _colors.primary.withOpacity(0.1);
6363
}
6464
if (states.contains(MaterialState.hovered)) {
65-
return ${componentColor('$tokenGroup.hover.state-layer')};
65+
return _colors.primary.withOpacity(0.08);
6666
}
6767
if (states.contains(MaterialState.focused)) {
68-
return ${componentColor('$tokenGroup.focus.state-layer')};
68+
return _colors.primary.withOpacity(0.1);
6969
}
7070
7171
return Colors.transparent;
7272
});
7373
7474
@override
75-
TextStyle? get valueIndicatorTextStyle => ${textStyle('$tokenGroup.label.label-text')}!.copyWith(
76-
color: ${componentColor('$tokenGroup.label.label-text')},
75+
TextStyle? get valueIndicatorTextStyle => ${textStyle('$tokenGroup.value-indicator.label.label-text')}!.copyWith(
76+
color: ${componentColor('$tokenGroup.value-indicator.label.label-text')},
7777
);
7878
7979
@override
80-
SliderComponentShape? get valueIndicatorShape => const DropSliderValueIndicatorShape();
80+
Color? get valueIndicatorColor => ${componentColor('$tokenGroup.value-indicator.container')};
81+
82+
@override
83+
SliderComponentShape? get valueIndicatorShape => const RoundedRectSliderValueIndicatorShape();
84+
85+
@override
86+
SliderComponentShape? get thumbShape => const HandleThumbShape();
87+
88+
@override
89+
SliderTrackShape? get trackShape => const GappedSliderTrackShape();
90+
91+
@override
92+
SliderComponentShape? get overlayShape => const RoundSliderOverlayShape();
93+
94+
@override
95+
SliderTickMarkShape? get tickMarkShape => const RoundSliderTickMarkShape(tickMarkRadius: ${getToken("$tokenGroup.stop-indicator.size")} / 2);
96+
97+
@override
98+
MaterialStateProperty<Size?>? get thumbSize {
99+
return MaterialStateProperty.resolveWith((Set<MaterialState> states) {
100+
if (states.contains(MaterialState.disabled)) {
101+
return const Size(${getToken("$tokenGroup.disabled.handle.width")}, ${getToken("$tokenGroup.handle.height")});
102+
}
103+
if (states.contains(MaterialState.hovered)) {
104+
return const Size(${getToken("$tokenGroup.hover.handle.width")}, ${getToken("$tokenGroup.handle.height")});
105+
}
106+
if (states.contains(MaterialState.focused)) {
107+
return const Size(${getToken("$tokenGroup.focus.handle.width")}, ${getToken("$tokenGroup.handle.height")});
108+
}
109+
if (states.contains(MaterialState.pressed)) {
110+
return const Size(${getToken("$tokenGroup.pressed.handle.width")}, ${getToken("$tokenGroup.handle.height")});
111+
}
112+
return const Size(${getToken("$tokenGroup.handle.width")}, ${getToken("$tokenGroup.handle.height")});
113+
});
114+
}
115+
116+
@override
117+
double? get trackGap => ${getToken("$tokenGroup.active.handle.padding")};
81118
}
82119
''';
83-
84120
}

0 commit comments

Comments
 (0)