How to draw a filled polygon - flutter

How to draw a filled polygon in flutter?
Currently I am able to a eyebrow shape with array of point like below.
Path leftEyePath = Path();
leftEyePath.moveTo(leftEye[0].getX(),leftEye[0].getY());//starting point
for(int i=1;i<leftEye.length;i++){
leftEyePath.lineTo(leftEye[i].getX(),leftEye[i].getY());
}
canvas.drawPath(leftEyePath,painter);
The code above will eventually draw a connected polygon with many line , but how do I draw a filled polygon with color I want?
EDIT:
I am currently go through their function and found drawShadow(..)
canvas.drawShadow(leftEyePath, Colors.orange[600],0,true);
Unfortunately it only draw transparent color.
Below is my current output.

You may change your paint style into PaintingStyle.fill. The paint brush will automatically fill up the closing area of your path.
Paint _filledPainter = new Paint()
..style = PaintingStyle.fill
;

Related

How to draw a circle filled with lines in Flutter

I am using canvas to draw circles in flutter, is there any easy way to draw circles filled with lines?
PS:I know I can calculate each line's points then drawing lines in circle. But is there any simple method that can be implemented without calculation?
This is what I want to achieve:
Finally, I found an easy and ingenious solution without calculation.
That is creating a linear gradient filled in the circle.
give two colors for the start and end of the gradient.
give transparent to the start color.
give the actual line color to the end color.
Paint paint = new Paint();
paint.color =Colors.red;
paint.style = PaintingStyle.fill;
paint.shader = ui.Gradient.linear(
start,
//the line interval is 20
Offset(start.dx + 20, start.dy),
[
//give transparent to start color, give actual line color to the end color
Colors. transparent,
Colors.red
],
//The interval [0.0,0.9] is transparent, and the interval [0.9,1.0] is red. So it looks like drawing red lines
[0.90, 1.0],
//just repeat the gradient
TileMode.repeated,
null);
canvas.drawCircle(
Offset(centerX, centerY),
radius,
paint);

How to fill a rectangle that has one side curved in flutter?

I'm trying to fill a curved rectangle, but it is overflowing from the curved part, have used paths to create this shape. Any suggestions for how to achieve this.
Or is there any way to create a rectangle with 4 offset values, whose one side is curved like this?
I have offset values of two straight line (x1,y1), (x2,y2), (x3,y3) and (x4,y4). Any references?
final path = Path();
path.moveTo(87.75, 10.06);
path.lineTo(263.25, 80.06);
path.lineTo(263.25, 359.0);
path.lineTo(87.75, 359.0);
canvasWrapper.drawPath(path, _barAreaPaint..color = Colors.red);
Try drawing an arc
Rect rect = Rect.fromLTWH(0.0, 0.0, size.width, size.height);
path.arcTo(
rect,
0.0,
pi / 2,//adjust radians accordingly
false);
}

iText 7 Adding colored text and fill to a rectangle

I am trying to add colored text to a rectangle and fill color in the rectangle but the
text seems to be behind the rectangle and so is not visible even though I can select it.
Paragraph = new Paragraph("The quick brown fox");
PdfCanvas canvas = new PdfCanvas(pdfDoc.addNewPage());
Rectangle rect = new Rectangle(ps.getWidth() - 90, ps.getHeight() - 100, 50, 50);
new Canvas(canvas, pdfDoc, rect)
.setFontColor(ColorConstants.WHITE)
.setFontSize(12)
.add(p);
canvas.rectangle(rect)
.setFillColor(ColorConstants.LIGHT_GRAY)
.fillStroke();
You first draw the text and then fill the rectangle. Thus, obviously the text ends up behind the rectangle.
Switch the order of your instructions, first fill the rectangle rect on your PdfCanvas canvas and then add the Paragraph p to the Canvas on canvas.

Flutter - Color of Overlapped Lines in Canvas

When I draw lines on a CustomPainter's canvas using code like this:
var paint = Paint()
..style = PaintingStyle.stroke
..strokeWidth = 4.0
..color = Colors.grey;
canvas.drawLine(fromOffsetA, toOffsetB, paint);
canvas.drawLine(fromOffsetC, toOffsetD, paint);
If the two lines partly overlap over one another, then the section of the lines that overlap show the line color as being darker than in the sections of the line that do not overlap.
I am guessing that this is by design so, my question is, how do I draw lines that overlap one another and at the same time prevent the lines' color from darkening in the overlapped sections?
I am thinking I need to set the paint's Blendmode to a specific value or something along those lines?

Add Dynamic LineColor To Biograph Matlab

Hey i am trying to paint the edges of a biograph, i want to paint each time a new edge and keep the previews painted edges.
Here is my code
A = sparse(6,6);
A(Router1,Router2)=bool;
ids = {'A','B','C','D','E','F'};
grp = view(biograph(A,ids));
if bool == 0
[dist,path,pred1] = graphshortestpath(A,Router1,Router2);
edges = getedgesbynodeid(grp,get(grp.Nodes(path),'ID'));
set(edges,'LineColor',[1 0 0])
set(edges,'LineWidth',1.5)
end
Ass you can see i get the wanted edge painted in red.
now i am tring to paint another edge but i cant find a way to save the already painted one.
i want thinking about saving the path but i couldn't find a way to do it.