Unverified Commit 91d88336 authored by Qun Cheng's avatar Qun Cheng Committed by GitHub

Added `Switch` Animation for Material 3 (#113090)

parent a5ee67ef
...@@ -202,6 +202,18 @@ class _SwitchConfigM3 with _SwitchConfig { ...@@ -202,6 +202,18 @@ class _SwitchConfigM3 with _SwitchConfig {
@override @override
double get trackWidth => ${tokens['md.comp.switch.track.width']}; double get trackWidth => ${tokens['md.comp.switch.track.width']};
// The thumb size at the middle of the track. Hand coded default based on the animation specs.
@override
Size get transitionalThumbSize => const Size(34, 22);
// Hand coded default based on the animation specs.
@override
int get toggleDuration => 300;
// Hand coded default based on the animation specs.
@override
double? get thumbOffset => null;
} }
'''; ''';
......
...@@ -148,10 +148,10 @@ void main() { ...@@ -148,10 +148,10 @@ void main() {
find.byType(Switch), find.byType(Switch),
paints paints
..rrect(color: Colors.blue[500]) ..rrect(color: Colors.blue[500])
..circle(color: const Color(0x33000000)) ..rrect(color: const Color(0x33000000))
..circle(color: const Color(0x24000000)) ..rrect(color: const Color(0x24000000))
..circle(color: const Color(0x1f000000)) ..rrect(color: const Color(0x1f000000))
..circle(color: Colors.yellow[500]), ..rrect(color: Colors.yellow[500]),
); );
await tester.tap(find.byType(Switch)); await tester.tap(find.byType(Switch));
...@@ -161,10 +161,10 @@ void main() { ...@@ -161,10 +161,10 @@ void main() {
Material.of(tester.element(find.byType(Switch))), Material.of(tester.element(find.byType(Switch))),
paints paints
..rrect(color: Colors.green[500]) ..rrect(color: Colors.green[500])
..circle(color: const Color(0x33000000)) ..rrect(color: const Color(0x33000000))
..circle(color: const Color(0x24000000)) ..rrect(color: const Color(0x24000000))
..circle(color: const Color(0x1f000000)) ..rrect(color: const Color(0x1f000000))
..circle(color: Colors.red[500]), ..rrect(color: Colors.red[500]),
); );
}); });
......
...@@ -147,15 +147,15 @@ void main() { ...@@ -147,15 +147,15 @@ void main() {
? (paints ? (paints
..rrect(color: defaultTrackColor) ..rrect(color: defaultTrackColor)
..rrect(color: themeData.colorScheme.outline) ..rrect(color: themeData.colorScheme.outline)
..circle(color: defaultThumbColor) ..rrect(color: defaultThumbColor)
..paragraph() ..paragraph()
) )
: (paints : (paints
..rrect(color: defaultTrackColor) ..rrect(color: defaultTrackColor)
..circle() ..rrect()
..circle() ..rrect()
..circle() ..rrect()
..circle(color: defaultThumbColor) ..rrect(color: defaultThumbColor)
) )
); );
// Size from MaterialTapTargetSize.shrinkWrap. // Size from MaterialTapTargetSize.shrinkWrap.
...@@ -168,14 +168,14 @@ void main() { ...@@ -168,14 +168,14 @@ void main() {
_getSwitchMaterial(tester), _getSwitchMaterial(tester),
material3 material3
? (paints ? (paints
..rrect(color: selectedTrackColor) ..rrect(color: selectedTrackColor)..rrect()
..circle(color: selectedThumbColor)..paragraph()) ..rrect(color: selectedThumbColor)..paragraph())
: (paints : (paints
..rrect(color: selectedTrackColor) ..rrect(color: selectedTrackColor)
..circle() ..rrect()
..circle() ..rrect()
..circle() ..rrect()
..circle(color: selectedThumbColor)) ..rrect(color: selectedThumbColor))
); );
// Switch with hover. // Switch with hover.
...@@ -295,13 +295,13 @@ void main() { ...@@ -295,13 +295,13 @@ void main() {
? (paints ? (paints
..rrect(color: defaultTrackColor) ..rrect(color: defaultTrackColor)
..rrect(color: themeData.colorScheme.outline) ..rrect(color: themeData.colorScheme.outline)
..circle(color: defaultThumbColor)..paragraph(offset: const Offset(12, 16))) ..rrect(color: defaultThumbColor)..paragraph(offset: const Offset(12, 16)))
: (paints : (paints
..rrect(color: defaultTrackColor) ..rrect(color: defaultTrackColor)
..circle() ..rrect()
..circle() ..rrect()
..circle() ..rrect()
..circle(color: defaultThumbColor)) ..rrect(color: defaultThumbColor))
); );
// Size from MaterialTapTargetSize.shrinkWrap. // Size from MaterialTapTargetSize.shrinkWrap.
expect(tester.getSize(find.byType(Switch)), material3 ? const Size(60.0, 40.0) : const Size(59.0, 40.0)); expect(tester.getSize(find.byType(Switch)), material3 ? const Size(60.0, 40.0) : const Size(59.0, 40.0));
...@@ -314,13 +314,13 @@ void main() { ...@@ -314,13 +314,13 @@ void main() {
material3 material3
? (paints ? (paints
..rrect(color: selectedTrackColor) ..rrect(color: selectedTrackColor)
..circle(color: selectedThumbColor)) ..rrect(color: selectedThumbColor))
: (paints : (paints
..rrect(color: selectedTrackColor) ..rrect(color: selectedTrackColor)
..circle() ..rrect()
..circle() ..rrect()
..circle() ..rrect()
..circle(color: selectedThumbColor)) ..rrect(color: selectedThumbColor))
); );
// Switch with hover. // Switch with hover.
...@@ -393,13 +393,13 @@ void main() { ...@@ -393,13 +393,13 @@ void main() {
? (paints ? (paints
..rrect(color: defaultTrackColor) ..rrect(color: defaultTrackColor)
..rrect(color: themeData.colorScheme.outline) ..rrect(color: themeData.colorScheme.outline)
..circle(color: defaultThumbColor)) ..rrect(color: defaultThumbColor))
: (paints : (paints
..rrect(color: defaultTrackColor) ..rrect(color: defaultTrackColor)
..circle() ..rrect()
..circle() ..rrect()
..circle() ..rrect()
..circle(color: defaultThumbColor)) ..rrect(color: defaultThumbColor))
); );
// Selected switch. // Selected switch.
...@@ -410,13 +410,13 @@ void main() { ...@@ -410,13 +410,13 @@ void main() {
material3 material3
? (paints ? (paints
..rrect(color: selectedTrackColor) ..rrect(color: selectedTrackColor)
..circle(color: selectedThumbColor)) ..rrect(color: selectedThumbColor))
: (paints : (paints
..rrect(color: selectedTrackColor) ..rrect(color: selectedTrackColor)
..circle() ..rrect()
..circle() ..rrect()
..circle() ..rrect()
..circle(color: selectedThumbColor)) ..rrect(color: selectedThumbColor))
); );
}); });
...@@ -532,13 +532,13 @@ void main() { ...@@ -532,13 +532,13 @@ void main() {
material3 material3
? (paints ? (paints
..rrect(color: localThemeTrackColor) ..rrect(color: localThemeTrackColor)
..circle(color: localThemeThumbColor)) ..rrect(color: localThemeThumbColor))
: (paints : (paints
..rrect(color: localThemeTrackColor) ..rrect(color: localThemeTrackColor)
..circle() ..rrect()
..circle() ..rrect()
..circle() ..rrect()
..circle(color: localThemeThumbColor)) ..rrect(color: localThemeThumbColor))
); );
}); });
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment