Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
91d88336
Unverified
Commit
91d88336
authored
Oct 12, 2022
by
Qun Cheng
Committed by
GitHub
Oct 12, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added `Switch` Animation for Material 3 (#113090)
parent
a5ee67ef
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
466 additions
and
183 deletions
+466
-183
switch_template.dart
dev/tools/gen_defaults/lib/switch_template.dart
+12
-0
switch.dart
packages/flutter/lib/src/material/switch.dart
+170
-42
switch_list_tile_test.dart
packages/flutter/test/material/switch_list_tile_test.dart
+8
-8
switch_test.dart
packages/flutter/test/material/switch_test.dart
+240
-97
switch_theme_test.dart
packages/flutter/test/material/switch_theme_test.dart
+36
-36
No files found.
dev/tools/gen_defaults/lib/switch_template.dart
View file @
91d88336
...
@@ -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;
}
}
'''
;
'''
;
...
...
packages/flutter/lib/src/material/switch.dart
View file @
91d88336
This diff is collapsed.
Click to expand it.
packages/flutter/test/material/switch_list_tile_test.dart
View file @
91d88336
...
@@ -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
]),
);
);
});
});
...
...
packages/flutter/test/material/switch_test.dart
View file @
91d88336
This diff is collapsed.
Click to expand it.
packages/flutter/test/material/switch_theme_test.dart
View file @
91d88336
...
@@ -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
))
);
);
});
});
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment