buildPath method
Implementation
Path buildPath(Offset offset, double width, double height) {
var angleRad = pi / 180 * decoration.bubbleMeta.angle;
double spineHeight = decoration.bubbleMeta.spineHeight;
var spineMoveX = spineHeight * tan(angleRad / 2);
double xb = (width - decoration.boxSize.width) / 2 +
decoration.boxSize.width / 2 -
spineMoveX;
double xbs = decoration.boxSize.width / 2;
double xbe = width - decoration.boxSize.width / 2 - spineMoveX;
Offset translation = switch (decoration.placement) {
Placement.top => Offset(xb, 0),
Placement.topStart => Offset(xbs, 0),
Placement.topEnd => Offset(xbe, 0),
Placement.bottom => Offset(xb, 0),
Placement.bottomStart => Offset(xbs, 0),
Placement.bottomEnd => Offset(xbe, 0),
Placement.left => Offset(
0,
(height - decoration.boxSize.height) / 2 +
decoration.boxSize.height / 2 -
spineMoveX),
Placement.leftStart =>
Offset(0, decoration.boxSize.height / 2 - spineMoveX),
Placement.leftEnd =>
Offset(0, height - decoration.boxSize.height / 2 - spineMoveX),
Placement.right => Offset(
0,
(height - decoration.boxSize.height) / 2 +
decoration.boxSize.height / 2 -
spineMoveX),
Placement.rightStart =>
Offset(0, decoration.boxSize.height / 2 - spineMoveX),
Placement.rightEnd =>
Offset(0, height - decoration.boxSize.height / 2 - spineMoveX),
};
var spineMoveY = spineHeight;
if (spineHeight != 0) {
if (decoration.placement == Placement.bottom ||
decoration.placement == Placement.bottomStart ||
decoration.placement == Placement.bottomEnd) {
return Path()
..moveTo(offset.dx + translation.dx, offset.dy + translation.dy)
..relativeLineTo(spineMoveX, -spineMoveY)
..relativeLineTo(spineMoveX, spineMoveY);
}
if (decoration.placement == Placement.top ||
decoration.placement == Placement.topStart ||
decoration.placement == Placement.topEnd) {
return Path()
..moveTo(
offset.dx + translation.dx, offset.dy + translation.dy + height)
..relativeLineTo(spineMoveX, spineMoveY)
..relativeLineTo(spineMoveX, -spineMoveY);
}
if (decoration.placement == Placement.rightStart ||
decoration.placement == Placement.right ||
decoration.placement == Placement.rightEnd) {
return Path()
..moveTo(offset.dx + translation.dx, offset.dy + translation.dy)
..relativeLineTo(-spineMoveY, spineMoveX)
..relativeLineTo(spineMoveY, spineMoveX);
}
if (decoration.placement == Placement.leftStart ||
decoration.placement == Placement.left ||
decoration.placement == Placement.leftEnd) {
return Path()
..moveTo(
offset.dx + translation.dx + width, offset.dy + translation.dy)
..relativeLineTo(spineMoveY, spineMoveX)
..relativeLineTo(-spineMoveY, spineMoveX);
}
}
return Path();
}