Open dan-leech opened 3 years ago
I've found the way to achieve this:
BlendMask(
opacity: _spotOpacity.value,
blendMode: _blendMode,
child: SvgPicture.asset('assets/triangle.svg'));
class BlendMask extends SingleChildRenderObjectWidget {
final BlendMode blendMode;
final double opacity;
const BlendMask({
required this.blendMode,
required Widget child,
this.opacity = 1.0,
Key? key,
}) : super(key: key, child: child);
@override
RenderObject createRenderObject(BuildContext context) =>
RenderBlendMask(blendMode, opacity);
@override
void updateRenderObject(BuildContext context, RenderBlendMask renderObject) {
renderObject
..blendMode = blendMode
..opacity = opacity;
}
}
class RenderBlendMask extends RenderProxyBox {
BlendMode blendMode;
double opacity;
RenderBlendMask(this.blendMode, this.opacity);
@override
void paint(PaintingContext context, Offset offset) {
context.canvas.saveLayer(
offset & size,
Paint()
..blendMode = blendMode
..color = Color.fromARGB((opacity * 255).round(), 255, 255, 255));
super.paint(context, offset);
context.canvas.restore();
}
}
Maybe I do not understand blending right... I have two svg with shapes of different colors.
What is working and how:
color:
param I see blend effect like colored squares instead shapes and no blending between different SvgPicture widgets.What's the proper way to achieve something like this between two different SvgPicture widgets?