fixed topbar shape

This commit is contained in:
Vadim 2022-10-24 23:24:52 +03:00
parent c70fd29cfc
commit 50bc17214d

View file

@ -1,45 +1,58 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:lightmeter/res/dimens.dart';
class TopBarShape extends CustomPainter { class TopBarShape extends CustomPainter {
final Color color; final Color color;
final Size appendixSize; final Size appendixSize;
final double radius;
TopBarShape({ TopBarShape({
required this.color, required this.color,
required this.appendixSize, required this.appendixSize,
required this.radius,
}); });
@override @override
void paint(Canvas canvas, Size size) { void paint(Canvas canvas, Size size) {
final paint = Paint()..color = color; final paint = Paint()..color = color;
final path = Path(); final path = Path();
final circularRadius = Radius.circular(radius); const circularRadius = Radius.circular(Dimens.borderRadiusL);
if (appendixSize.shortestSide == 0) {
path.addRRect(
RRect.fromLTRBAndCorners(
0,
0,
0,
0,
bottomLeft: circularRadius,
bottomRight: circularRadius,
),
);
} else {
path.moveTo(size.width, 0); path.moveTo(size.width, 0);
path.lineTo(size.width, size.height - radius); path.lineTo(size.width, size.height - Dimens.borderRadiusL);
path.arcToPoint( path.arcToPoint(
Offset(size.width - radius, size.height), Offset(size.width - Dimens.borderRadiusL, size.height),
radius: circularRadius, radius: circularRadius,
); );
path.lineTo(size.width - appendixSize.width + radius, size.height); path.lineTo(size.width - appendixSize.width + Dimens.borderRadiusL, size.height);
path.arcToPoint( path.arcToPoint(
Offset(size.width - appendixSize.width, size.height - radius), Offset(size.width - appendixSize.width, size.height - Dimens.borderRadiusL),
radius: circularRadius, radius: circularRadius,
); );
path.lineTo(size.width - appendixSize.width, size.height - appendixSize.height + radius); path.lineTo(size.width - appendixSize.width, size.height - appendixSize.height + Dimens.borderRadiusM);
path.arcToPoint( path.arcToPoint(
Offset(size.width - appendixSize.width - radius, size.height - appendixSize.height), Offset(size.width - appendixSize.width - Dimens.borderRadiusM, size.height - appendixSize.height),
radius: circularRadius, radius: circularRadius,
clockwise: false, clockwise: false,
); );
path.lineTo(radius, size.height - appendixSize.height); path.lineTo(Dimens.borderRadiusL, size.height - appendixSize.height);
path.arcToPoint( path.arcToPoint(
Offset(0, size.height - appendixSize.height - radius), Offset(0, size.height - appendixSize.height - Dimens.borderRadiusL),
radius: circularRadius, radius: circularRadius,
); );
path.lineTo(0, 0); path.lineTo(0, 0);
path.close(); path.close();
}
canvas.drawPath(path, paint); canvas.drawPath(path, paint);
} }