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
),
),
);
}
Author by
Maoration
Updated on December 27, 2022Comments
-
Maoration over 1 year
With the deprecated
RaisedButton
class, it was easy to create a gradient background for a button using thedecoration
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 todecoration
.So, any suggestions?
-
Maoration about 3 yearsApparently, 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.