Unverified Commit 114f05ce authored by Vasiliy Ditsyak's avatar Vasiliy Ditsyak Committed by GitHub

Add fallback font to IconData class (#127269)

This PR adds an ability to specify `fallbackFont` for `Icon` class via `IconData` props.

Read detailed description here https://github.com/flutter/flutter/issues/126670
parent 764f4cc8
......@@ -280,6 +280,7 @@ class Icon extends StatelessWidget {
fontSize: iconSize,
fontFamily: icon!.fontFamily,
package: icon!.fontPackage,
fontFamilyFallback: icon!.fontFamilyFallback,
shadows: iconShadows,
),
),
......
......@@ -31,6 +31,7 @@ class IconData {
this.fontFamily,
this.fontPackage,
this.matchTextDirection = false,
this.fontFamilyFallback,
});
/// The Unicode code point at which this icon is stored in the icon font.
......@@ -56,6 +57,11 @@ class IconData {
/// [Directionality] is [TextDirection.rtl].
final bool matchTextDirection;
/// The ordered list of font families to fall back on when a glyph cannot be found in a higher priority font family.
///
/// For more details, refer to the documentation of [TextStyle]
final List<String>? fontFamilyFallback;
@override
bool operator ==(Object other) {
if (other.runtimeType != runtimeType) {
......@@ -65,11 +71,20 @@ class IconData {
&& other.codePoint == codePoint
&& other.fontFamily == fontFamily
&& other.fontPackage == fontPackage
&& other.matchTextDirection == matchTextDirection;
&& other.matchTextDirection == matchTextDirection
&& listEquals(other.fontFamilyFallback, fontFamilyFallback);
}
@override
int get hashCode => Object.hash(codePoint, fontFamily, fontPackage, matchTextDirection);
int get hashCode {
return Object.hash(
codePoint,
fontFamily,
fontPackage,
matchTextDirection,
Object.hashAll(fontFamilyFallback ?? const <String?>[]),
);
}
@override
String toString() => 'IconData(U+${codePoint.toRadixString(16).toUpperCase().padLeft(5, '0')})';
......
......@@ -127,6 +127,20 @@ void main() {
expect(richText.text.style!.fontFamily, equals('Roboto'));
});
testWidgets('Icon with custom fontFamilyFallback', (WidgetTester tester) async {
await tester.pumpWidget(
const Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: Icon(IconData(0x41, fontFamilyFallback: <String>['FallbackFont'])),
),
),
);
final RichText richText = tester.firstWidget(find.byType(RichText));
expect(richText.text.style!.fontFamilyFallback, equals(<String>['FallbackFont']));
});
testWidgets('Icon with semantic label', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);
......
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