CirclePainterV2 class
A custom painter that draws a semi-transparent overlay with a circular cutout and optional progress arc, typically used as an overlay for selfie cameras to focus on the subject in the center of the screen.
The CirclePainterV2 class is designed to paint an overlay on the screen with a clear circle in the center,
making it suitable for use in selfie camera applications, or any use case that requires a circular overlay.
Additionally, it supports drawing a progress arc around the circle, which can be useful for indicating capture progress.
Customization:
topMargin: Adjust the vertical position of the circle.circleRadius: A callback function that determines the radius of the circle based on the screen size.progress: A value between 0.0 and 1.0 that controls the portion of the progress arc to be drawn around the circle. For example, 0.25 represents a quarter circle, 0.5 represents half, and 1.0 represents a full circle.strokeWidth: Customize the thickness of the circle stroke and progress arc.strokeColor: Define the color of the circle's stroke (default is white).overlayColor: Change the color and opacity of the overlay surrounding the circle.progressColor: Set the color of the progress arc (default is green).
Usage Example:
Here's how you can use the CirclePainterV2 in a camera preview setup, typically for selfies:
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Camera Selfie Page", style: TextStyle(color: Colors.black)),
),
body: Stack(
children: [
// Camera preview area
Container(
alignment: Alignment.center,
child: cameraController?.value.isInitialized == true
? CameraPreview(cameraController!)
: Container(),
),
// Circular overlay for selfie capture
IgnorePointer(
child: CustomPaint(
painter: CirclePainterV2(
progress: 0.5, // Draw half of the progress arc (optional)
),
child: Container(),
),
),
],
),
);
}
This painter is useful for creating a focused circular overlay for selfie or face-related captures, and the progress arc can be used for visual feedback during actions like countdowns or photo captures.
For more detailed examples, refer to the example.
- Inheritance
-
- Object
- Listenable
- CustomPainter
- CirclePainterV2
Constructors
Properties
- circleRadius ↔ double? Function(Size size)?
-
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
- overlayColor ↔ Color?
-
getter/setter pair
- progress ↔ double
-
getter/setter pair
- progressColor ↔ Color
-
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- semanticsBuilder → SemanticsBuilderCallback?
-
Returns a function that builds semantic information for the picture drawn
by this painter.
no setterinherited
- strokeColor ↔ Color
-
getter/setter pair
- strokeWidth ↔ double
-
getter/setter pair
- topMargin ↔ double?
-
getter/setter pair
Methods
-
addListener(
VoidCallback listener) → void -
Register a closure to be notified when it is time to repaint.
inherited
-
hitTest(
Offset position) → bool? -
Called whenever a hit test is being performed on an object that is using
this custom paint delegate.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
paint(
Canvas canvas, Size size) → void -
Called whenever the object needs to paint. The given Canvas has its
coordinate space configured such that the origin is at the top left of the
box. The area of the box is the size of the
sizeargument.override -
removeListener(
VoidCallback listener) → void -
Remove a previously registered closure from the list of closures that the
object notifies when it is time to repaint.
inherited
-
shouldRebuildSemantics(
covariant CustomPainter oldDelegate) → bool -
Called whenever a new instance of the custom painter delegate class is
provided to the RenderCustomPaint object, or any time that a new
CustomPaint object is created with a new instance of the custom painter
delegate class (which amounts to the same thing, because the latter is
implemented in terms of the former).
inherited
-
shouldRepaint(
covariant CustomPainter oldDelegate) → bool -
Called whenever a new instance of the custom painter delegate class is
provided to the RenderCustomPaint object, or any time that a new
CustomPaint object is created with a new instance of the custom painter
delegate class (which amounts to the same thing, because the latter is
implemented in terms of the former).
override
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited