-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
Is there an existing issue for this?
- I have searched the existing issues
- I have read the guide to filing a bug
Use case
Hello 👋
For our specific use case, we wanted to add a (radial) gradient background to the button.
What we tried
Using the button's child property required us to both remove the button's paddings (otherwise it doesn't touch the button's edges) and to expand it internally (which was causing layout issues).
What we had to do to make it work
- Copied the whole
ButtonStyleButtonimplementation, - replaced this
ConstrainedBoxfor aContainer - Created a subclass of
ButtonStylewith an addedfinal MaterialStateProperty<Decoration?>? decorationproperty (when the button is disabled, the gradient changes color as well) - added a
resolvedeffectiveDecoration& insert it to theContainerabove
Proposal
The existing ButtonStyleButton & ButtonStyle already allow many configuration options.
Suggested proposals would be to add a dedicated Gradient property, or to be more generic and use a Decoration property instead.
One important note on my solution: since the Container is above Material, which handles the clipping behavior, the Decoration might also need special handling to the resolved shape.
One simple way would be just to check for an existing resolved decoration and do conditional widget wrapping(s)?