GlassProxyPainter class abstract Capture control
Draws a stand-in for a subtree in the proxy, for GlassProxy.replace.
Deliberately shaped like CustomPainter, including the runtimeType
comparison in front of shouldRepaint — this is the same problem and there
is no reason to make it look like a different one. Two differences, both
deliberate:
- The canvas is clipped to
sizebefore paint runs. ACustomPainterthat overdraws produces a visible artefact somebody notices; a stub that overdraws corrupts the backdrop of surfaces elsewhere on the screen, with no visual signal anywhere and no pixel test that would catch it. - isOpaque is read, and answering true makes the stub an occlusion cover as well as a substitution.
SolidProxyPainter and GradientProxyPainter cover the common cases. A painter of one's own:
class MapTilePainter extends GlassProxyPainter {
const MapTilePainter(this.land, this.water);
final Color land;
final Color water;
@override
void paint(Canvas canvas, Size size) {
canvas
..drawRect(Offset.zero & size, Paint()..color = land)
..drawRect(Rect.fromLTWH(0, size.height * 0.6, size.width, size.height * 0.4), Paint()..color = water);
}
@override
bool shouldRepaint(MapTilePainter oldPainter) => oldPainter.land != land || oldPainter.water != water;
@override
bool get isOpaque => land.a >= 1 && water.a >= 1;
}
See also:
- GlassProxy.replace, which takes one.
- Capture control on the site.
- Implementers
Constructors
- GlassProxyPainter()
-
Lets subclasses be
const.const
Properties
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
paint(
Canvas canvas, Size size) → void -
Paints the stand-in. Local space: the subtree's origin is
Offset.zero, exactly as inCustomPainter. -
shouldRepaint(
covariant GlassProxyPainter oldPainter) → bool -
Whether the proxy has to be re-recorded because this painter replaced
oldPainter. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited