Skip to content

Commit abc02ce

Browse files
authored
Merge pull request #261 from JudahMcNicholl/SharpIcon
Fix to use Sharp Icons
2 parents 01bac00 + d790bfd commit abc02ce

File tree

3 files changed

+87
-7
lines changed

3 files changed

+87
-7
lines changed

lib/src/icon_data.dart

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,55 @@ class IconDataThin extends IconData {
7777
fontPackage: 'font_awesome_flutter',
7878
);
7979
}
80+
81+
/// [IconData] for a font awesome sharp thin icon from a code point. Only works if
82+
/// thin icons (font awesome pro, v6+) have been installed.
83+
///
84+
/// Code points can be obtained from fontawesome.com
85+
class IconDataSharpThin extends IconData {
86+
const IconDataSharpThin(int codePoint)
87+
: super(
88+
codePoint,
89+
fontFamily: 'FontAwesomeSharpThin',
90+
fontPackage: 'font_awesome_flutter',
91+
);
92+
}
93+
94+
/// [IconData] for a font awesome sharp light icon from a code point. Only works if
95+
/// thin icons (font awesome pro, v6+) have been installed.
96+
///
97+
/// Code points can be obtained from fontawesome.com
98+
class IconDataSharpLight extends IconData {
99+
const IconDataSharpLight(int codePoint)
100+
: super(
101+
codePoint,
102+
fontFamily: 'FontAwesomeSharpLight',
103+
fontPackage: 'font_awesome_flutter',
104+
);
105+
}
106+
107+
/// [IconData] for a font awesome sharp regular icon from a code point. Only works if
108+
/// thin icons (font awesome pro, v6+) have been installed.
109+
///
110+
/// Code points can be obtained from fontawesome.com
111+
class IconDataSharpRegular extends IconData {
112+
const IconDataSharpRegular(int codePoint)
113+
: super(
114+
codePoint,
115+
fontFamily: 'FontAwesomeSharpRegular',
116+
fontPackage: 'font_awesome_flutter',
117+
);
118+
}
119+
120+
/// [IconData] for a font awesome sharp solid icon from a code point. Only works if
121+
/// thin icons (font awesome pro, v6+) have been installed.
122+
///
123+
/// Code points can be obtained from fontawesome.com
124+
class IconDataSharpSolid extends IconData {
125+
const IconDataSharpSolid(int codePoint)
126+
: super(
127+
codePoint,
128+
fontFamily: 'FontAwesomeSharpSolid',
129+
fontPackage: 'font_awesome_flutter',
130+
);
131+
}

pubspec.yaml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,20 @@ flutter:
4343
# - family: FontAwesomeThin
4444
# fonts:
4545
# - asset: lib/fonts/fa-thin-100.ttf
46-
# weight: 100
46+
# weight: 100
47+
# - family: FontAwesomeSharpThin
48+
# fonts:
49+
# - asset: lib/fonts/fa-sharp-thin-100.ttf
50+
# weight: 100
51+
# - family: FontAwesomeSharpLight
52+
# fonts:
53+
# - asset: lib/fonts/fa-sharp-light-300.ttf
54+
# weight: 300
55+
# - family: FontAwesomeSharpRegular
56+
# fonts:
57+
# - asset: lib/fonts/fa-sharp-regular-400.ttf
58+
# weight: 400
59+
# - family: FontAwesomeSharpSolid
60+
# fonts:
61+
# - asset: lib/fonts/fa-sharp-solid-900.ttf
62+
# weight: 900

util/lib/main.dart

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ void adjustPubspecFontIncludes(Set<String> styles) {
194194
if (!line.trimLeft().startsWith('- family:')) continue;
195195

196196
styleName = line.substring(25).toLowerCase(); // - family: FontAwesomeXXXXXX
197-
if (styles.contains(styleName)) {
197+
if (styles.any((element) => element.replaceAll(' ', '') == styleName)) { //Because of 'sharp thin' we need to remove spaces here
198198
pubspec[i] = uncommentYamlLine(pubspec[i]);
199199
pubspec[i + 1] = uncommentYamlLine(pubspec[i + 1]);
200200
pubspec[i + 2] = uncommentYamlLine(pubspec[i + 2]);
@@ -445,7 +445,7 @@ String normalizeIconName(String iconName, String style, int styleCompetitors) {
445445

446446
/// Utility function to generate the correct 'IconData' subclass for a [style]
447447
String styleToDataSource(String style) {
448-
return 'IconData${style[0].toUpperCase()}${style.substring(1)}';
448+
return 'IconData${style.split(' ').map((word) => word.isNotEmpty ? word[0].toUpperCase() + word.substring(1) : '').toList().join('')}';
449449
}
450450

451451
/// Gets the default branch from github's metadata
@@ -556,13 +556,25 @@ bool readAndPickMetadata(File iconsJson, List<IconMetadata> metadata,
556556
versions.add(v);
557557
}
558558

559-
List<String> iconStyles = (icon['styles'] as List).cast<String>();
560-
559+
List<String> iconStyles = [];
560+
if (icon.containsKey("styles")) {
561+
iconStyles = (icon['styles'] as List).cast<String>();
562+
} else if (icon.containsKey("svgs")) {
563+
iconStyles.addAll((icon['svgs']['classic'] as Map<String, dynamic>).keys);
564+
if (icon['svgs']?['sharp'] != null) {
565+
iconStyles.addAll((icon['svgs']['sharp'] as Map<String, dynamic>).keys.map((key) => 'sharp $key')); //"sharp thin ..."
566+
}
567+
}
561568
//TODO: Remove line once duotone support discontinuation notice is removed
562569
if (iconStyles.contains('duotone')) hasDuotoneIcons = true;
563570

564571
for (var excluded in excludedStyles) {
565-
iconStyles.remove(excluded);
572+
if (excluded == 'sharp') {
573+
//Since it's 'sharp thin' then remove any containing sharp
574+
iconStyles.removeWhere((element) => element.contains('sharp'));
575+
} else {
576+
iconStyles.remove(excluded);
577+
}
566578
}
567579

568580
if (iconStyles.isEmpty) continue;
@@ -628,7 +640,7 @@ ArgParser setUpArgParser() {
628640
argParser.addMultiOption('exclude',
629641
abbr: 'e',
630642
defaultsTo: [],
631-
allowed: ['brands', 'regular', 'solid', 'duotone', 'light', 'thin'],
643+
allowed: ['brands', 'regular', 'solid', 'duotone', 'light', 'thin', 'sharp'],
632644
help: 'icon styles which are excluded by the generator');
633645

634646
argParser.addFlag('dynamic',

0 commit comments

Comments
 (0)