Use flutter Icon class by code

Asked

Viewed 38 times

0

Good night!

I’m getting the code from a flutter icon as per the documentation below: https://pub.dev/documentation/flutter_for_web/latest/material/Icons-class.html

Therefore, as documentation to use the icon add box I must use the following code:

const IconData(0xe146, fontFamily: 'MaterialIcons')

So I applied it to my app:

Icon(
    IconData(0xe146, fontFamily: 'MaterialIcons'),
    size: constraints.maxHeight * .035,
    color: Colors.white,)

But when running the app the icon shown is another and not add_box, as shown below: icon trocado

1 answer

1


The page you are browsing,

https://pub.dev/documentation/flutter_for_web/latest/material/Icons-class.html

If you notice correctly, it is not the official Flutter documentation page. It starts with pub.dev which indicates that it is a custom package that should be used as a dependency (and included in your file pubspec.yaml). The name of this package is flutter_for_web. I believe that this was not your intention, but even if it was, by clicking on the top left corner of the page and going to the package page, we see that it has been discontinued. It has only had one version since it was released and has never been updated.

For the icon class of the material design included in Flutter, use the official documentation (from flutter.dev website):

Icon(
    IconData(57419, fontFamily: 'MaterialIcons'),
    size: constraints.maxHeight * .035,
    color: Colors.white,)

However, it is worth making it clear that choose the icon by the number directly nay is the most appropriate way to use, as in a future version these values may change.

I don’t know if you had any reason for this choice, but I recommend using the value of the constant directly:

Icon(
    Icons.add_box,
    size: constraints.maxHeight * .035,
    color: Colors.white,)

The documentation page linked above makes this clear in bold:

Do not use codepoints directly, as they are Subject to change.

Do not use the code points directly as they are subject to change. (Free translation)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.