createShader method
Creates a shader that tiles this pattern.
Implementation
Shader createShader(Rect bounds) {
final recorder = ui.PictureRecorder();
final canvas = Canvas(recorder);
final size = Size(width, height);
// Draw background
if (backgroundColor.a > 0) {
canvas.drawRect(
Rect.fromLTWH(0, 0, width, height),
Paint()..color = backgroundColor,
);
}
// Draw pattern
drawPattern(canvas, size);
final picture = recorder.endRecording();
final image = picture.toImageSync(width.ceil(), height.ceil());
return ImageShader(
image,
TileMode.repeated,
TileMode.repeated,
Matrix4.identity().storage,
);
}