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
e7c867c9
Unverified
Commit
e7c867c9
authored
Aug 09, 2022
by
Pierre-Louis
Committed by
GitHub
Aug 09, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for font variation based theming to `Icon` (#109140)
parent
f3d182f4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
5 deletions
+69
-5
icon.dart
packages/flutter/lib/src/widgets/icon.dart
+12
-4
icon_test.dart
packages/flutter/test/widgets/icon_test.dart
+57
-1
No files found.
packages/flutter/lib/src/widgets/icon.dart
View file @
e7c867c9
...
...
@@ -240,6 +240,14 @@ class Icon extends StatelessWidget {
final
double
?
iconSize
=
size
??
iconTheme
.
size
;
final
double
?
iconFill
=
fill
??
iconTheme
.
fill
;
final
double
?
iconWeight
=
weight
??
iconTheme
.
weight
;
final
double
?
iconGrade
=
grade
??
iconTheme
.
grade
;
final
double
?
iconOpticalSize
=
opticalSize
??
iconTheme
.
opticalSize
;
final
List
<
Shadow
>?
iconShadows
=
shadows
??
iconTheme
.
shadows
;
if
(
icon
==
null
)
{
...
...
@@ -262,10 +270,10 @@ class Icon extends StatelessWidget {
text:
String
.
fromCharCode
(
icon
!.
codePoint
),
style:
TextStyle
(
fontVariations:
<
FontVariation
>[
if
(
fill
!=
null
)
FontVariation
(
'FILL'
,
fill
!
),
if
(
weight
!=
null
)
FontVariation
(
'wght'
,
weight
!
),
if
(
grade
!=
null
)
FontVariation
(
'GRAD'
,
grade
!
),
if
(
opticalSize
!=
null
)
FontVariation
(
'opsz'
,
opticalSize
!
),
if
(
iconFill
!=
null
)
FontVariation
(
'FILL'
,
iconFill
),
if
(
iconWeight
!=
null
)
FontVariation
(
'wght'
,
iconWeight
),
if
(
iconGrade
!=
null
)
FontVariation
(
'GRAD'
,
iconGrade
),
if
(
iconOpticalSize
!=
null
)
FontVariation
(
'opsz'
,
iconOpticalSize
),
],
inherit:
false
,
color:
iconColor
,
...
...
packages/flutter/test/widgets/icon_test.dart
View file @
e7c867c9
...
...
@@ -220,7 +220,12 @@ void main() {
);
RichText
text
=
tester
.
widget
(
find
.
byType
(
RichText
));
expect
(
text
.
text
.
style
!.
fontVariations
,
<
FontVariation
>[]);
expect
(
text
.
text
.
style
!.
fontVariations
,
<
FontVariation
>[
const
FontVariation
(
'FILL'
,
0.0
),
const
FontVariation
(
'wght'
,
400.0
),
const
FontVariation
(
'GRAD'
,
0.0
),
const
FontVariation
(
'opsz'
,
48.0
)
]);
await
tester
.
pumpWidget
(
const
Directionality
(
...
...
@@ -239,6 +244,57 @@ void main() {
]);
});
testWidgets
(
'Fill, weight, grade, and optical size can be set at the theme-level'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
const
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
IconTheme
(
data:
IconThemeData
(
fill:
0.2
,
weight:
3.0
,
grade:
4.0
,
opticalSize:
5.0
,
),
child:
Icon
(
Icons
.
abc
),
),
),
);
final
RichText
text
=
tester
.
widget
(
find
.
byType
(
RichText
));
expect
(
text
.
text
.
style
!.
fontVariations
,
<
FontVariation
>[
const
FontVariation
(
'FILL'
,
0.2
),
const
FontVariation
(
'wght'
,
3.0
),
const
FontVariation
(
'GRAD'
,
4.0
),
const
FontVariation
(
'opsz'
,
5.0
)
]);
});
testWidgets
(
'Theme-level fill, weight, grade, and optical size can be overriden'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
const
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
IconTheme
(
data:
IconThemeData
(
fill:
0.2
,
weight:
3.0
,
grade:
4.0
,
opticalSize:
5.0
,
),
child:
Icon
(
Icons
.
abc
,
fill:
0.6
,
weight:
7.0
,
grade:
8.0
,
opticalSize:
9.0
),
),
),
);
final
RichText
text
=
tester
.
widget
(
find
.
byType
(
RichText
));
expect
(
text
.
text
.
style
!.
fontVariations
,
isNotNull
);
expect
(
text
.
text
.
style
!.
fontVariations
,
<
FontVariation
>[
const
FontVariation
(
'FILL'
,
0.6
),
const
FontVariation
(
'wght'
,
7.0
),
const
FontVariation
(
'GRAD'
,
8.0
),
const
FontVariation
(
'opsz'
,
9.0
)
]);
});
test
(
'Throws if given invalid values'
,
()
{
expect
(()
=>
Icon
(
Icons
.
abc
,
fill:
-
0.1
),
throwsAssertionError
);
expect
(()
=>
Icon
(
Icons
.
abc
,
fill:
1.1
),
throwsAssertionError
);
...
...
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