rotatedTextSize function
This method returns the rect for given size and angle
Implementation
Rect rotatedTextSize(Size size, int angle) {
final Rect rect = Rect.fromLTWH(0, 0, size.width, size.height);
final vector.Matrix2 _rotatorMatrix =
vector.Matrix2.rotation(degreeToRadian(angle));
final Rect movedToCenterAsOrigin = rect.shift(-rect.center);
Offset _topLeft = movedToCenterAsOrigin.topLeft;
Offset _topRight = movedToCenterAsOrigin.topRight;
Offset _bottomLeft = movedToCenterAsOrigin.bottomLeft;
Offset _bottomRight = movedToCenterAsOrigin.bottomRight;
_topLeft = transform(_rotatorMatrix, _topLeft);
_topRight = transform(_rotatorMatrix, _topRight);
_bottomLeft = transform(_rotatorMatrix, _bottomLeft);
_bottomRight = transform(_rotatorMatrix, _bottomRight);
final List<Offset> rotOffsets = <Offset>[
_topLeft,
_topRight,
_bottomLeft,
_bottomRight
];
final double minX =
rotOffsets.map((Offset offset) => offset.dx).reduce(math.min);
final double maxX =
rotOffsets.map((Offset offset) => offset.dx).reduce(math.max);
final double minY =
rotOffsets.map((Offset offset) => offset.dy).reduce(math.min);
final double maxY =
rotOffsets.map((Offset offset) => offset.dy).reduce(math.max);
final Rect rotateRect = Rect.fromPoints(
Offset(minX, minY),
Offset(maxX, maxY),
);
return rotateRect;
}