Flutter ShaderMask usage details

Climbers aiming for the top will not be intoxicated by a certain footprint along the way. In the world of code farmers, the beautiful application experience comes from the programmer's handling of details and the realm of self-requirements. Young people are also busy One of the busy code farmers, every day and every week, will leave some footprints. It is the content of these creations. There is a kind of persistence. I don’t know why. If you are confused, you might as well take a look at the track of the code farmers.

If you are interested, you can follow the public account biglead to get the latest learning materials.


Renderings of this article

insert image description here

core code

ShaderMask(
   blendMode: BlendMode.srcATop,
       shaderCallback: (Rect bounds) {
    
    
         return const LinearGradient(
           colors: [Colors.orange, Colors.yellow],
         ).createShader(bounds);
       },
       child: Image.asset(
         'assets/images/qq_icon.png',
         width: 40,
       ),
    )

page code

class Exam220HomePage extends StatefulWidget {
    
    
  const Exam220HomePage({
    
    Key? key}) : super(key: key);

  @override
  State<Exam220HomePage> createState() => _Exam220HomePageState();
}

class _Exam220HomePageState extends State<Exam220HomePage> {
    
    
  @override
  Widget build(BuildContext context) {
    
    
    return Scaffold(
      //页面的主内容区
      body: Center(
        child: Row(
          mainAxisSize: MainAxisSize.min,
          children: [
            Image.asset(
              'assets/images/qq_icon.png',
              width: 40,
            ),
            SizedBox(
              width: 0100,
            ),

            ///代码清单2-28
            ShaderMask(
              blendMode: BlendMode.srcATop,
              shaderCallback: (Rect bounds) {
    
    
                return const LinearGradient(
                  colors: [Colors.orange, Colors.yellow],
                ).createShader(bounds);
              },
              child: Image.asset(
                'assets/images/qq_icon.png',
                width: 40,
              ),
            )
          ],
        ),
      ),
    );
  }
}

If you are confused, you might as well come here to share every day, and then accumulate
more Widget applications. The editor has summarized them in the book.


insert image description here


Guess you like

Origin blog.csdn.net/zl18603543572/article/details/123314618