This is the native and correct way to create a gradient background for the ElevatedButton using backgroundBuilder!
Code Sample:
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundBuilder: (context, state, child) {
return Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: [Colors.purple, Colors.blue],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
),
child: const Icon(Icons.apple),
);
},
),
child: const Icon(Icons.apple),
onPressed: () {},
)
Good coding! 🩵