Skip to content

Instantly share code, notes, and snippets.

@digitaljoni
Created March 17, 2020 02:02
Show Gist options
  • Select an option

  • Save digitaljoni/1ad947b17f1898f19db74546485674e0 to your computer and use it in GitHub Desktop.

Select an option

Save digitaljoni/1ad947b17f1898f19db74546485674e0 to your computer and use it in GitHub Desktop.
Gradient Icon Widget
class GradientIcon extends StatelessWidget {
GradientIcon(
this.icon,
this.size,
this.gradient,
);
final IconData icon;
final double size;
final Gradient gradient;
@override
Widget build(BuildContext context) {
return ShaderMask(
child: SizedBox(
width: size * 1.2,
height: size * 1.2,
child: Icon(
icon,
size: size,
color: Colors.white,
),
),
shaderCallback: (Rect bounds) {
final Rect rect = Rect.fromLTRB(0, 0, size, size);
return gradient.createShader(rect);
},
);
}
}
@caiusCitiriga
Copy link

Great widget. Thank you ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment