Flutter: ElevatedButton with gradient background

221

Wrap a Container with a GestureDetector

The GestureDetector will give you to onTap functionality. The Container will provide the decoration

 @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onPressed,
      child: Container(
        decoration: BoxDecoration(
         // Decorate here
        ),
        child: Center(
          // Enter content here
        ),
      ),
    );
  }
Share:
221
Maoration
Author by

Maoration

Updated on December 27, 2022

Comments

  • Maoration
    Maoration over 1 year

    With the deprecated RaisedButton class, it was easy to create a gradient background for a button using the decoration property, and using the different Gradient classes with an array of Colors.

    However, using the new and improved (?) ElevatedButton class, I just cant figure out how to accomplish this. Every bit of online information refers to the deprecated use cases, and digging through the API docs I cant find something equivalent to decoration.

    So, any suggestions?

  • Maoration
    Maoration about 3 years
    Apparently, the new ElevatedButton and OutlinedButton widgets do not support custom graphics and animation, so the only option is to do it 'vanilla' as described above. thanks for your answer.