How to create a gradient button in flutter

I am trying to create a button similar to this one, I don’t have exact colors so using yellow and black.

Want this

enter image description here

My Code Output

enter image description here

here is my code:

class CustomButton extends StatelessWidget {
  final String? text;
  double width;
  final Function()? onPressed;
  CustomButton({this.width = 0.8, this.text, this.onPressed});
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onPressed,
      child: Container(
        child: Center(
            child: CustomTextWidget(
          text: text!,
          textColor: AppColors.BLACK_COLOR,
          fontWeight: FontWeight.bold,
          fontSize: 1.1,
        height: ScreenSize.heightSize * 0.08,
        width: width.sw,
        decoration: BoxDecoration(
            gradient: const LinearGradient(
              colors: [Colors.yellow,],
              begin: Alignment.topRight,
              end: Alignment.topRight,
              stops: [0.7, 0.8],
              tileMode: TileMode.repeated,
            borderRadius: BorderRadius.circular(4)),

Kindly help how to do this.

>Solution :

Try below code hope its help to you and used FractionalOffset

  onTap: () {},
  child: Container(
    height: 44.0,
    width: 100,
    decoration: const BoxDecoration(
      gradient: LinearGradient(
        colors: [
        begin: FractionalOffset.bottomCenter,
        end: FractionalOffset.topCenter,
    child: const Text('SIGN UP'),

Result-> image

Leave a Reply