Custom Shapes and Drawing in Flutter Apps Using Painters

With Canvas and Paint we can change the look of a certain widget. That is done using a CustomPainter, which is a class that allows us to draw lines and shapes on a virtual Canvas.

CustomPaint

CustomPaint is the widget that allows us to insert the custom shapes we’ll create using a CustomPainter into the widget tree. It takes two arguments: a CustomPainter as the named painter and a child widget, which will be the widget on which the effect will be applied. For example, if we wanted to paint a Flutter logo widget using a custom painter we’ll create called LogoPainter, we’d insert the following into the widget tree:

 CustomPaint(
  painter: LogoPainter(),
  child: FlutterLogo(),
 ),

Creating ...

Get Programming Flutter now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.