Closed JCKodel closed 4 months ago
Hello @JCKodel - I am not completely understanding what you are trying to accomplish. I took a look at your package and it looks nice.
Could you explain more about what you are trying to accomplish?
The symbols_map,dart
file looks like this:
Map<String, IconData> materialSymbolsMap = {
'ten_k': Symbols.ten_k,
'ten_k_rounded': Symbols.ten_k_rounded,
'ten_k_sharp': Symbols.ten_k_sharp,
...
It is basically a map like you describe, but containing all 3 of the versions of each icon (outlined, rounded and sharp).
I have been thinking of moving the symbols_map.dart
file to the main package so that it would be available to reference for users that need a map of all icons. If it wasn't included it would not effect tree shaking, but if it was included it would trigger the including of every icon in the fonts.
Basically, at run-time, I need to get the package name, font name and unicode code of a string, such as "add_circle".
The Markdown extension will then render a Text using those info to actually
render the icon (it doesn't need nor should know what is Symbols
).
In other words: given a String, I need to use a simple Text
widget that
is able to render it (for example, an Icon(Icons.add)
will actually
render to Text(String.fromCharCode(icon.codePoint), style: TextStyle(package: icon.fontPackage, fontFamily: icon.fontFamily))
). The
Icon
widget never knows what IconData
package it receives (the same
would be true for the markdown extension, except the markdown will contain
a text, such as ten_k
that I would need to render as the Text
above,
without knowing about Symbols
consts (introspection is soooo needed for
Dart :( ))
For this particular font package, the ideal would be a Map<String, IconData>
with all icons (since IconData
is const, it will not duplicate
the package and font names and also will not create any issues with Icon
treeshaking).
On Sun, Dec 17, 2023 at 12:05 AM Tim Maffett @.***> wrote:
Hello @JCKodel https://github.com/JCKodel - I am not completely understanding what you are trying to accomplish. I took a look at your package and it looks nice.
Could you explain more about what you are trying to accomplish?
The symbols_map,dart file looks like this:
Map<String, IconData> materialSymbolsMap = { 'ten_k': Symbols.ten_k, 'ten_k_rounded': Symbols.ten_k_rounded, 'ten_k_sharp': Symbols.ten_k_sharp,
...
It is basically a map like you describe, but containing all 3 of the versions of each icon (outlined, rounded and sharp).
I have been thinking of moving the symbols_map.dart file to the main package so that it would be available to reference for users that need a map of all icons. If it wasn't included it would not effect tree shaking, but if it was included it would trigger the including of every icon in the fonts.
— Reply to this email directly, view it on GitHub https://github.com/timmaffett/material_symbols_icons/issues/16#issuecomment-1859022924, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAC4TS2V3WZAEAZHFO4TFTDYJZOQTAVCNFSM6AAAAABAVRLAACVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNJZGAZDEOJSGQ . You are receiving this because you were mentioned.Message ID: @.***>
Hi @JCKodel - it seems like there may be another solution that will certainly be safe (as far as not preventing tree shaking), and that is to provide something like this:
const Map<String,int> iconCodePoints = {
'add' : 0xff33,
...
};
const String iconFontPacklage='....';
const String iconFontFamily='....';
This would create the minimum static data and the iconCodePoints map would be identical for all 3 symbols fonts (outline,rounded and sharp)..
Would something like that work ? You are just starting with the icon's name string correct ?
@timmaffett That would work perfectly!
OK, version 4.2716.0 is being released today and I now generate a file lib\iconname_to_unicode_map.dart
which has a map that looks like this:
Map<String, int> materialSymbolsIconNameToUnicodeMap = {
'ten_k' : 0xe951,
'ten_mp' : 0xe952,
'eleven_mp' : 0xe953,
...
};
You could be able to include the file with
import 'package:material_symbols_icons/iconname_to_unicode_map.dart';
I did not include the package or font name as these can be found in the package itself and did not seem to be a useful addition.
@JCKodel - Let me know how it works!
Just perfect! Thank you!
Now I'll be able to
[i:ten_k]
Notice: this is not the same as #6!
I have a https://pub.dev/packages/markdown_viewer plugin that draws icons using a markdown extension:
[i:font_package:font_name:codepoint:color]
.I was wondering if it would be possible to generate those information in a map, such as:
This way, I cound simplify the markdown extension to
[i:ten_k]
to show theten_k
icon on aText
widget.I think this would not mess with the treeshaking process.