LaVOZs

The World’s Largest Online Community for Developers

'; dart - How to create ImageShader in Flutter? - LavOzs.Com

I was playing with ShaderMask and it accepts two types of Shaders

Gradient & ImageShader

I can create Gradient Shader like this :

LinearGradient(colors: <Color>[
                      Colors.deepOrange,
                      Colors.blue,
                      Colors.green,
                      Colors.amber,
                    ]).createShader(bound)

but I couldn't find a way to create ImageShader.

When I try to create it like this :

ImageShader(
                    Image.network(
                      "https://product-image.juniqe-production.juniqe.com/media/catalog/product/cache/x800/401/62/401-62-101P.jpg",
                    ),
                    TileMode.mirror,
                    TileMode.mirror,
                    Float64List.fromList([1.0, 1, 0, 1, 1, 1, 1, 1, 0]));
              }

it says : Argument type widget/Image can't be assigned to parameter type ui/Painting/Image

I know these two Images are different but I couldn't create ui/Painting/Image from widget/Image.

Also there might be an intuitive way to create ImageShader?

What is the right way to crate ImageShader in Flutter?

There are two classes called Image in flutter, in different packages.

There's the Widget, which behaves like a widget and can be instantiated from an asset, from memory or from the network through its named constructors.

There's also the ui package Image which is used when painting at a lower level

import 'dart:ui' as ui;

Example:

 ImageShader(
   Image.network(
      "https://product-image.juniqe-production.juniqe.com/media/catalog/product/cache/x800/401/62/401-62-101P.jpg",
   ),
   TileMode.mirror,
   TileMode.mirror,
   Float64List.fromList([1.0, 1, 0, 1, 1, 1, 1, 1, 0]),
 );
Related
How to create Toast in Flutter?
How to add a border to a widget in Flutter?
How to change the app display name build with flutter?
How to create number input field in Flutter?
Create a rounded button / button with border-radius in Flutter
How do I use hexadecimal color strings in Flutter?
How to access camera frames in flutter quickly
How to change package name in flutter?