I need to put a gradient on my Icon
.
How do I achieve this?
One way to do this is to use a ShaderMask widget. If you wrap an icon with this, you can apply any gradient you like:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: LinearGradientMask(
child: Icon(
Icons.book,
size: 250,
color: Colors.white,
),
),
),
),
);
}
}
class LinearGradientMask extends StatelessWidget {
LinearGradientMask({this.child});
final Widget child;
@override
Widget build(BuildContext context) {
return ShaderMask(
shaderCallback: (bounds) {
return RadialGradient(
center: Alignment.topLeft,
radius: 1,
colors: [Colors.blue, Colors.red],
tileMode: TileMode.mirror,
).createShader(bounds);
},
child: child,
);
}
}
giving you something like looks like this:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With