patterns_canvas library

A utility library that lets you paint Canvas shapes or widgets with patterns like dots, stripes, squares, etc.:

Simple Example

Inside your CustomPainter class's paint method, create a Pattern class with background (bgColor) and foreground (fgColor) colors and use one of its paintOn methods:

class MyPainter extends CustomPainter {
  @override
  void paint(Canvas canvas, Size size) {

    // Prepare a rectangle shape to draw the pattern on.
    final rect = Rect.fromLTWH(80, 50, 200, 100);

    // Create a Pattern object of diagonal stripes with the colors we want.
    final Pattern pattern = DiagonalStripesLight(bgColor: Colors.lightGreenAccent, fgColor: Colors.black);

    // Paint the pattern on the rectangle.
    pattern.paintOnRect(canvas, size, rect);

  }
}

Enums

PatternScaleBehavior
Changes how the pattern is drawn on the Canvas shape or Widget. Used in the paintOn methods of each Pattern.
PatternType
The available Pattern types. Use in the Pattern.fromValues constructor.