Add support for font variation based theming to Icon
(#109140)
This commit is contained in:
parent
f3d182f4b4
commit
e7c867c916
@ -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,
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user