I am working on an app which requires me to save flutter material icons to the database. The problem is how.
This question here mentions one way, which is to use the IconData
attribute codePoint
. But in this github issue, it is mentioned that codePoint
s are not recommended as they are prone to changes.
With no other ways, currently I am working on a flutter plugin, specifically this.
It maps the flutter icons using the names. Like, {"question_mark" : Icons.question_mark}
, and it does that for all of them. All around 9000 of them which were in the flutter's material/icons.dart
file.
Now the problem is that with so many icons, the plugin is getting heavy on size while slow on work. I have added in to filter only base variant icons, like remove 'sharp', 'outlined', etc. variants, and ended up with 2000 something. But the problem is still there, it is slow. I am now planning to do the operations in separate isolates and handle them as futures. That's all I could do.
But is there anything else that can be done? Is there a way with which this entire thing could just be removed. Something better. If not, any ideas on how I can make the code faster?
class IconsCatalog {
String? getName(IconData icon) {
final String? name = primaryIconNameMap[icon];
if (name != null) return name;
return duplicatedIconNameMap[icon];
}
IconData? getIconData(String name, {bool isBase = false}) {
if (isBase) {
return baseIconMap[name];
}
return iconMap[name];
}
List<IconData> getIconDataList({bool includeVariants = true}) {
if (includeVariants) return iconMap.values.toList();
return baseIconMap.values.toList();
}
}
Can't paste out thousands of lines of map data, so here is just the operations being done. I haven't yet made them run on isolates. You could check the repository link above to see the other code but there is nothing other than the maps.
Thank you