Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IconDecoration's gradient property doesn't work anymore #3

Closed
MeixDev opened this issue Mar 10, 2022 · 2 comments · Fixed by #4
Closed

IconDecoration's gradient property doesn't work anymore #3

MeixDev opened this issue Mar 10, 2022 · 2 comments · Fixed by #4
Assignees
Labels
bug Something isn't working

Comments

@MeixDev
Copy link

MeixDev commented Mar 10, 2022

Hi!

The package was working fine last time I tested it a few months ago, but it now seems to be incapable of rendering any gradients. It seems the last color used in the gradient is the one used to paint the whole widget.

@TesteurManiak TesteurManiak self-assigned this Mar 10, 2022
@TesteurManiak TesteurManiak added the bug Something isn't working label Mar 10, 2022
@TesteurManiak
Copy link
Owner

I've been able to reproduce this bug with the following test:

Code

void main() {
  group('Goldens Issue #3', () {
    goldenTest(
      "IconDecoration's gradient property doesn't work anymore",
      fileName: 'issue_3',
      widget: GoldenTestGroup(
        children: [
          GoldenTestScenario(
            name: 'with rainbow gradient',
            child: const DecoratedIcon(
              icon: Icon(Icons.all_inbox, size: 50),
              decoration: IconDecoration(
                gradient: rainbowGradient,
              ),
            ),
          ),
          GoldenTestScenario(
            name: 'same rainbow gradient',
            child: const DecoratedIcon(
              icon: Icon(Icons.all_inbox, size: 50),
              decoration: IconDecoration(
                gradient: rainbowGradient,
              ),
            ),
          ),
        ],
      ),
    );
  });
}

Golden

issue_3

Seems like it is an issue with the gradient's boundaries when creating the shader for the gradient:

if (gradient != null) {
  iconStyle = iconStyle.copyWith(
    foreground: Paint()
      ..shader = gradient.createShader(
        Rect.fromLTWH(0, 0, iconSize, iconSize),
      ),
  );
}

@TesteurManiak
Copy link
Owner

TesteurManiak commented Mar 11, 2022

I've created a custom widget to render Icon with a gradient, it might change a bit the way a gradient is rendered because now its boundaries are correct.

All related test can be found in gradient_test.dart, you should obtain a result similar to this:

gradient_rendering

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants