Creating a Flutter Custom Gradient Button

Maneesha Erandi
2 min readMay 22

In this article, I will explain how to create a Custom Gradient Button with Flutter widgets. If you are a beginner wondering how to add a GradientButton to your UI, well this article is for you.

You can learn about available Material design buttons with this article.

I use the LinearGradient widget to create the gradient button.

Properties of a LinearGradient

The list of colors is the only required argument here. As you can see, the default begin alignment is centerLeft while the end is centerRight.

  const LinearGradient({
this.begin = Alignment.centerLeft,
this.end = Alignment.centerRight,
required super.colors,
this.tileMode = TileMode.clamp,

Create a Gradient Button with ClipRRect widget.

When we use a ClipRRect to create a custom button, we can stack a Container with a gradient decoration and a TextButton which has a onPressed function and Material design button styles.

So we have to pass the Stack widget as the child of the ClipRRect. We can use the Positioned.fill widget to wrap the container. Then we can use the BoxDecoration gradient param, to pass a LinearGradient with a list of colors.

class GradientButton extends StatelessWidget {
const GradientButton({Key? key}) : super(key: key);

Widget build(BuildContext context) {
return ClipRRect(
borderRadius: BorderRadius.circular(4),
child: Stack(
children: <Widget>[
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: <Color>[
style: TextButton.styleFrom(
foregroundColor: Colors.white…
Maneesha Erandi

I write about mobile development and wildlife.