I am working on a Flutter project and I want to create a button with a gradient background that includes both an image and text. However, I am not sure how to achieve this.
I have tried to make it like this image:
I have tried using the MaterialButton widget and setting its shape property to a RoundedRectangleBorder with gradient color, but I cannot figure out how to add the image and text to the button.
Can someone please provide me with an example of how to create a gradient button with an image and text in Flutter? Additionally, is there a way to customize the gradient colors of the button?
2
Answers
Just use
Stack
widget with 3 children (from lowest to highest):Image
Container
withdecoration.gradient
of semi-transparent colorsText
If you wish you could wrap entire
Stack
inClipRRect
to add rounded corners.To add button behaviour, you could use custom
GestureDetector
orInkWell
Desired Code:
Usage: