-
-
Notifications
You must be signed in to change notification settings - Fork 475
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add gradient border support for Button and FilledButton #956
Conversation
I create a new class named `RoundedRectangleGradientBorder`, which extends `ShapeBorder` class in package: flutter/painting.dart. This class draws on the original `RoundedRectangleBorder` class, only changing ‘side’ to ‘gradient’, ‘width’, and ‘strokeAlign’. At the same time, I also override the `paint` method, assigning ‘gradient’ to ‘paint.shader’ to draw a gradient border. I am not familiar with your project's structure, so I put the different border style in the file `rounded_rectangle_gradient_border.dart`. The style is copy from [Windows UI 3](https://www.figma.com/community/file/1159947337437047524/windows-ui-3).
This is awesome! I'd love to work on this, do you mind if I commit to your branch? This is an awesome start, but some things need to be addressed:
|
Never mind. |
Copy from Windows UI 3 Light Mode FilledButton
Button
Dark Mode FilledButton
Button
|
…on, works. prodused a small bug in ToggleButton * Add `style` property. Same with `RoundedRectangleBorder`, used `BorderStyle.solid` as default. To omit the border, use `BorderStyle.none`. * in `base.dart`, `_BaseButtonState`, `build` method: Remove `resolvedBorder`. Because we don't need `BorderSide` in `RoundedRectangelGradientBorder`; Change `OutlinedBorder` to `ShapeBorder` so it can support `RoundedRectangelGradientBorder`; * in `color_resources.dart`. Add `controlBorderGradient`, `accentControlBorderGradient`. The first is used by Button when rest or hover, while the second is used by FilledButton when rest or hover; When they're disabled or pressed, the gradient change to color with opacity. With that change, it looks like being pressed in Light Mode. In Dark Mode, the gradient is just like normol color with opacity. It seems that we don't neet apply gradient border when Dark Mode is used. * These changes are test in example app. Work as thought. **I modified the `lerp` method in `ButtonStyle` by simply changing `OutlinedBorder` to `RoundedRectangleGradientBorder`. I don't kown how it works, so I can't test it. I am not sure it will work.** * **Changes in `Button` produses a bug in `ToggleButton`. When state change between pressed and rest, the high changed. It seems to use different border when state changes, I couldn't find where the style set, so I don't kown how to fix it.**
Hey @Ferry-200! Thank you so much for this PR, it is really good. I commit a few changes, please tell me if there's anything you want to change. Thank you, looking forward to it |
Hello @bdlukaa , I think there's nothing need to change. Thank you so much for these commit. I learned very much. By the way, I wonder that how do you think about this minor break. Is it easy to migrate? |
yes, it actually is! I added a migration guide on the changelog. |
This pr is for #920.
I am creating a new class called
RoundedRectangleGradientBorder
, which extends theShapeBorder
class inpackage: flutter/painting.dart
. You can use it whereverRoundedRectangleBorder
can be used.This class is similar to the original
RoundedRectangleBorder
class, except that I changedside
togradient
,width
andstrokeAlign
. At the same time I override the paint method and assigngradient
topaint.shader
to draw a gradient border.I am not familiar with the structure of your project, so I put the different border style in the
rounded_rectangle_gradient_border.dart
file. The style is copied from Windows UI 3.In my test, it works like this:

The WindowsUI 3 in Figma Windows UI 3:

The test code is:
Pre-launch Checklist
CHANGELOG.md
with my changes