flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
166.2k stars 27.49k forks source link

Allow setting the paint used on icons #38908

Open dnfield opened 5 years ago

dnfield commented 5 years ago

For example, if you wanted to draw a stroked icon rather than filled, it is not possible without custom code today. We should allow specifying a foreground paint on icons, which would allow for specifying shaders or stroke/fill styles.

adriancmurray commented 5 years ago

Adding the foreground property to the Icon class should be very straightforward as it's just a wrapper for RichText. This would also give the ability to create shadows on icons. While this is being done I recommend making a small modification to the build method. Currently it looks like this:

return Semantics(
      label: semanticLabel,
      child: ExcludeSemantics(
        child: SizedBox(
          width: iconSize,
          height: iconSize,
          child: Center(
            child: iconWidget,
          ),
        ),
      ),
    );

This would result in some changes to how icons are rendered as a whole but changing it to something like the below code will fix some of the problems with alignment on certain icon packages. For instance, FontAwesomeIcons doesn't center very well as the icons go outside of the bounding box.

return Semantics(
      label: semanticLabel,
      child: ExcludeSemantics(
        child: SizedBox(
            width: iconSize,
            height: iconSize,
            child: FittedBox(
              alignment: Alignment.center,
              child: iconWidget,
            )
        ),
      ),
    );

I also think that a more simplified version of the Icon widget would be to create its own TextPainter to sidestep the creation of an entire RichText component all to render a single character in it's given TextSpan. Just my two cents.

rostopira commented 5 years ago

Yeah, I were asked to make outline icon or at least shadow, and I just said - I can't Whatever I tried, it won't work

UPD: well, I've modified source of Icon