icon_gradient.dart

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: RadiantGradientMask( child: Icon( Icons.book, size: 250, color: Colors.white, ), ), ), ), ); } } class RadiantGradientMask extends StatelessWidget { RadiantGradientMask({this.child}); final Widget child; @override Widget build(BuildContext context) { return ShaderMask( shaderCallback: (bounds) => RadialGradient( center: Alignment.center, radius: 0.5, colors: [Colors.blue, Colors.red], tileMode: TileMode.mirror, ).createShader(bounds), child: child, ); } }
Apply a color gradient to an icon in Flutter

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.