From 1576f5b9c40379529c1469b1e90ffdd4b73286bd Mon Sep 17 00:00:00 2001 From: vishnukvmd Date: Thu, 14 Sep 2023 17:55:37 +0530 Subject: [PATCH 1/2] Make colors optional --- lib/ui/utils/icon_utils.dart | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/ui/utils/icon_utils.dart b/lib/ui/utils/icon_utils.dart index 1a0ec3edc1..a6555be0e3 100644 --- a/lib/ui/utils/icon_utils.dart +++ b/lib/ui/utils/icon_utils.dart @@ -12,7 +12,7 @@ class IconUtils { // Map of icon-title to the color code in HEX final Map _simpleIcons = {}; - final Map _customIcons = {}; + final Map _customIcons = {}; Future init() async { await _loadJson(); @@ -27,14 +27,14 @@ class IconUtils { return _getSVGIcon( "assets/custom-icons/icons/$title.svg", title, - _customIcons[title]!, + _customIcons[title], width, ); } else if (_simpleIcons.containsKey(title)) { return _getSVGIcon( "assets/simple-icons/icons/$title.svg", title, - _simpleIcons[title]!, + _simpleIcons[title], width, ); } else { @@ -45,17 +45,19 @@ class IconUtils { Widget _getSVGIcon( String path, String title, - String color, + String? color, double width, ) { return SvgPicture.asset( path, width: width, semanticsLabel: title, - colorFilter: ColorFilter.mode( - Color(int.parse("0xFF" + color)), - BlendMode.srcIn, - ), + colorFilter: color != null + ? ColorFilter.mode( + Color(int.parse("0xFF" + color)), + BlendMode.srcIn, + ) + : null, ); } From 42d2b17b985d65da0a42f2620670713fca85efd0 Mon Sep 17 00:00:00 2001 From: vishnukvmd Date: Thu, 14 Sep 2023 18:08:17 +0530 Subject: [PATCH 2/2] Support slugs --- lib/ui/utils/icon_utils.dart | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/ui/utils/icon_utils.dart b/lib/ui/utils/icon_utils.dart index a6555be0e3..a1a9246585 100644 --- a/lib/ui/utils/icon_utils.dart +++ b/lib/ui/utils/icon_utils.dart @@ -12,7 +12,7 @@ class IconUtils { // Map of icon-title to the color code in HEX final Map _simpleIcons = {}; - final Map _customIcons = {}; + final Map _customIcons = {}; Future init() async { await _loadJson(); @@ -25,9 +25,9 @@ class IconUtils { final title = _getProviderTitle(provider); if (_customIcons.containsKey(title)) { return _getSVGIcon( - "assets/custom-icons/icons/$title.svg", + "assets/custom-icons/icons/${_customIcons[title]!.slug ?? title}.svg", title, - _customIcons[title], + _customIcons[title]!.color, width, ); } else if (_simpleIcons.containsKey(title)) { @@ -72,7 +72,10 @@ class IconUtils { .loadString('assets/custom-icons/_data/custom-icons.json'); final customIcons = json.decode(customIconData); for (final icon in customIcons["icons"]) { - _customIcons[icon["title"].toString().toLowerCase()] = icon["hex"]; + _customIcons[icon["title"].toString().toLowerCase()] = CustomIconData( + icon["slug"], + icon["hex"], + ); } } @@ -80,3 +83,10 @@ class IconUtils { return provider.split(RegExp(r'[.(]'))[0].trim().toLowerCase(); } } + +class CustomIconData { + final String? slug; + final String? color; + + CustomIconData(this.slug, this.color); +}