font_awesome_flutter icon indicating copy to clipboard operation
font_awesome_flutter copied to clipboard

Icon not centered in FaIcon when used as prefix icon

Open SeriousMonk opened this issue 5 years ago • 14 comments

I have a TextFormField and am using the FaIcon widget as prefix icon:

TextFormField(
     decoration: InputDecoration(
         border: InputBorder.none,
         contentPadding: EdgeInsets.only(top: 14.0),
         prefixIcon: FaIcon(
             FontAwesomeIcons.penNib,
             color: themeOrangeColor,
         ),
    ),
)

This results in the FontAwesomeIcon to be aligned top-left inside the FaIcon widget like so: Capture

Any Idea to why this happens?

SeriousMonk avatar Nov 10 '20 12:11 SeriousMonk

Out of curiosity: does this happen with material icons as well? You may need to wrap the icon in an Align widget

michaelspiss avatar Nov 10 '20 12:11 michaelspiss

Using Icon instead of FaIcon fixed it. Thanks!

SeriousMonk avatar Nov 10 '20 12:11 SeriousMonk

Reopening, this seems to be a bug with FaIcon

michaelspiss avatar Nov 11 '20 12:11 michaelspiss

You can use it like below, this will align it correctly.

prefixIcon: const Padding(
   padding: EdgeInsets.all(10.0),
   child: FaIcon(FontAwesomeIcons.penNib, color: themeOrangeColor),
),

callawey avatar Mar 05 '21 18:03 callawey

I just published version 10.0.0-beta on pub, which should resolve this issue. However, since this is a change to FaIcon, I'd like to make sure everything works as expected - even in cases I did not think of in my tests. It'd be great if some of you could check if everything works in your apps and maybe leave some feedback. Thanks!

michaelspiss avatar Oct 21 '21 12:10 michaelspiss

So, I just tried your beta version and it still seems a bit off. This is my rough setup for my input fields in my main.yml:

  ThemeData _getTheme() {
    final ThemeData theme = ThemeData();

    return theme.copyWith(
      [...],
      inputDecorationTheme: InputDecorationTheme(
        labelStyle: TextStyle(
          color: Color(0xff555555),
        ),
        enabledBorder: UnderlineInputBorder(
          borderSide: BorderSide(color: Get.theme.dividerColor),
        ),
        focusedBorder: UnderlineInputBorder(
          borderSide: BorderSide(color: Get.theme.dividerColor),
        ),
        border: UnderlineInputBorder(
          borderSide: BorderSide(
            color: Color(0xff888888),
          ),
        ),
      ),
    );
  }

This is an example in one of my widgets:

TextFormField(
  controller: controller.passwordController,
  decoration: InputDecoration(
    // prefixIcon: Icon(Icons.lock, color: Get.theme.dividerColor),
    prefixIcon: FaIcon(FontAwesomeIcons.lock,
        color: Get.theme.dividerColor),
    labelText: "Passwort",
  ),
  autocorrect: false,
  enableSuggestions: false,
  obscureText: true,
  autofocus: true,
),

When using the commented line (so using a "normal" icon instead of FaIcons) I'll get the following result: 1

But with FaIcons I get the following: 2

So the FaIcon seems to be too high. Not sure if I gave enough information to reproduce. Hit me up if you need more info.

stedekay avatar Oct 26 '21 13:10 stedekay

First of all, thanks for your help @stedekay! It looks like in this case the widget still acts like before... I guess it needs a bit more tinkering

michaelspiss avatar Oct 26 '21 21:10 michaelspiss

@stedekay this is what your code looks like for me: Screenshot_20211207-232034.jpg FaIcon on top, Material Icon on the bottom

michaelspiss avatar Dec 07 '21 22:12 michaelspiss

Mmh, interesting. Maybe I made a mistake while upgrading my setup (I am using Font Awesome Pro and had problems with upgrading). So I'll have to give it another go.

Thanks for looking at it again!

stedekay avatar Dec 13 '21 16:12 stedekay

I just published version 10.0.0-beta on pub, which should resolve this issue. However, since this is a change to FaIcon, I'd like to make sure everything works as expected - even in cases I did not think of in my tests. It'd be great if some of you could check if everything works in your apps and maybe leave some feedback. Thanks!

Hi there,

I just installed FontAwesomeIcon (4.7), solution with padding is working. However if we don't apply any padding, this is not working and the bug seems to be there

EpiSayLaCata avatar Jan 17 '22 11:01 EpiSayLaCata

Hi @EpiSayLaCata, thanks for testing. Can you give a short code example for an issue with the padding which worked in version 9.2.0 or with material's Icon? Preferably with a screenshot.

michaelspiss avatar Jan 18 '22 13:01 michaelspiss

The fix seems to work, but I've noticed quite a performance penalty - especially when many icons are used. I've opened up an issue over at flutter/flutter#99830 intending to make FaIcon obsolete. This also means that the fix will not ship with version 10 of this package.

michaelspiss avatar Mar 17 '22 14:03 michaelspiss

Issue is still in v10.1.0, as expected. Switching to Icon instead of FaIcon as others suggested fixed the issue. It would be nice if the actual Icon class supported non 1:1 aspect ratios...

GregoryConrad avatar Jul 30 '22 04:07 GregoryConrad

I had a fix ready, but it was too resource intensive to be a viable option.

The proposal regarding rectangular icon support is linked above your comment, please upvote it, so it gets a higher priority from the flutter team.

I'd love to get rid of FaIcon as well.

michaelspiss avatar Jul 30 '22 10:07 michaelspiss