avatarAnnsh Singh

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

1997

Abstract

s="gist-iframe" src="/gist/annshsingh/65659af8119adb93278b2cef36e20f39.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined"> </div> </div> </figure></iframe></div></div></figure><p id="aa99">Below is the visual representation of the code above.</p><figure id="1478"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*nzB75Ciewrr29z97NjDhVQ.png"><figcaption></figcaption></figure><h2 id="7750">3 | Explanation</h2><p id="f777">In the example above, we have a Text widget and a FlutterLogo widget with Gradients applied to them using ShaderMask widget. It is done by simply wrapping those widgets with ShaderMask and providing it with a Gradient (can be Linear, Radial or Sweep) via its <b>shaderCallback </b>property. The shaderCallback is called with the current size of the child of ShaderMask (here, Text and FlutterLogo widgets) so that it can customize the shader to the size and location of the child. The <b>createShader </b>method of the Gradient classes in Flutter is used to create a shader using the bounds passed on to the <b>shaderCallback </b>property (as can be seen in the code snippet above).</p><p id="bf00">Also, do keep in mind to pass color as white to the child widgets of ShaderMask to see the desired result.</p><div id="943d" class="link-block"> <a href="https://readmedium.com/flutter-widget-guide-listwheelscrollview-widget-in-5-mins-or-less-c1da452355d2"> <div> <div> <h2>Flutter Widget Guide — ListWheelScrollView Widget in 5 mins or less</h2> <div><h3>This is Part 18 in the series where I’ll cover all the Flutter widgets that are in this YouTube playlist. I have…</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*896aOmL9-up_HAp7MRzLQA.png)"></div> </div>

Options

</div> </a> </div><p id="1f62"><b>Previous </b>👆</p><h2 id="8ca2">How many claps does this article deserve?</h2><p id="1554"><i>If you find this article useful, please <b>click the </b></i>👏<b><i> button</i></b><i> <b>and share </b>to help others find it! Feel free to clap many times (10</i>💥<i>, 20</i>💥<i> or maybe 50</i>💥<i> ?) It fuels my focus to write more of it.</i></p><p id="6ac8">Connect with me on <a href="https://www.linkedin.com/in/annsh/">LinkedIn</a> or say hi on <a href="https://mobile.twitter.com/annsh2013">Twitter</a>, mentioning this article. You can drop an e-mail at [email protected] as well.</p><p id="6551">See more in the series -</p><div id="9d85" class="link-block"> <a href="https://readmedium.com/flutter-widget-guide-index-f03141793b09"> <div> <div> <h2>Flutter Widget Guide — Index</h2> <div><h3>Hey. I created this series for flutter developers out there who wish to explore a widget with an example. All the…</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*OcqcC1Bh78wle2NG)"></div> </div> </div> </a> </div><p id="24a8">Have a wonderful day 🙂</p><div id="224c" class="link-block"> <a href="https://www.twitter.com/FlutterComm"> <div> <div> <h2>Flutter Community</h2> <div><h3>The latest Tweets from Flutter Community (@FlutterComm). Follow to get notifications of new articles and packages from…</h3></div> <div><p>www.twitter.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*_KwLA3J_b5nYSMZC)"></div> </div> </div> </a> </div></article></body>

Flutter Widget Guide — ShaderMask Widget in 5 mins or less

This is Part 19 in the series where I’ll cover all the Flutter widgets that are in this YouTube playlist. I have created my own widget guide which I believe will help people who are new in this space. Please have a look at this GitHub project to explore all the amazing widgets.

Click here to the App available on Google Play Store. 📱

My main motive behind this series is to keep things to the point. Your time is precious, let’s not waste it and get started.

It is always fun to use Gradients inside your applications. They are visually appealing and helps giving your views a modern look and feel (when used adequately). In flutter, there are ways to give Container widget a gradient using BoxDecoration widget and providing it with Linear, Radial or Sweep gradient. To apply gradient to widgets like Text or Image etc, flutter has a widget prepared for you to use.

ShaderMask Widget

1 | What?

This widget is helpful when you want to apply shaders to views like a Text widget. You can use this widget to apply Gradients or Images to other widgets just by wrapping them with this and providing a shader you wish to apply.

2 | Wondering how it works?

Have a look at the Code snippet below.

Below is the visual representation of the code above.

3 | Explanation

In the example above, we have a Text widget and a FlutterLogo widget with Gradients applied to them using ShaderMask widget. It is done by simply wrapping those widgets with ShaderMask and providing it with a Gradient (can be Linear, Radial or Sweep) via its shaderCallback property. The shaderCallback is called with the current size of the child of ShaderMask (here, Text and FlutterLogo widgets) so that it can customize the shader to the size and location of the child. The createShader method of the Gradient classes in Flutter is used to create a shader using the bounds passed on to the shaderCallback property (as can be seen in the code snippet above).

Also, do keep in mind to pass color as white to the child widgets of ShaderMask to see the desired result.

Previous 👆

How many claps does this article deserve?

If you find this article useful, please click the 👏 button and share to help others find it! Feel free to clap many times (10💥, 20💥 or maybe 50💥 ?) It fuels my focus to write more of it.

Connect with me on LinkedIn or say hi on Twitter, mentioning this article. You can drop an e-mail at [email protected] as well.

See more in the series -

Have a wonderful day 🙂

Flutter
Flutter Widget
Dart
Programming
Application Development
Recommended from ReadMedium