From 50bc17214ddfcc4cf8ea969ec8fd3cb6d9eba219 Mon Sep 17 00:00:00 2001 From: Vadim <44135514+vodemn@users.noreply.github.com> Date: Mon, 24 Oct 2022 23:24:52 +0300 Subject: [PATCH] fixed topbar shape --- .../components/topbar/topbar_shape.dart | 67 +++++++++++-------- 1 file changed, 40 insertions(+), 27 deletions(-) diff --git a/lib/screens/metering/components/topbar/topbar_shape.dart b/lib/screens/metering/components/topbar/topbar_shape.dart index 2de8036..b729d46 100644 --- a/lib/screens/metering/components/topbar/topbar_shape.dart +++ b/lib/screens/metering/components/topbar/topbar_shape.dart @@ -1,45 +1,58 @@ import 'package:flutter/material.dart'; +import 'package:lightmeter/res/dimens.dart'; class TopBarShape extends CustomPainter { final Color color; final Size appendixSize; - final double radius; TopBarShape({ required this.color, required this.appendixSize, - required this.radius, }); @override void paint(Canvas canvas, Size size) { final paint = Paint()..color = color; final path = Path(); - final circularRadius = Radius.circular(radius); - path.moveTo(size.width, 0); - path.lineTo(size.width, size.height - radius); - path.arcToPoint( - Offset(size.width - radius, size.height), - radius: circularRadius, - ); - path.lineTo(size.width - appendixSize.width + radius, size.height); - path.arcToPoint( - Offset(size.width - appendixSize.width, size.height - radius), - radius: circularRadius, - ); - path.lineTo(size.width - appendixSize.width, size.height - appendixSize.height + radius); - path.arcToPoint( - Offset(size.width - appendixSize.width - radius, size.height - appendixSize.height), - radius: circularRadius, - clockwise: false, - ); - path.lineTo(radius, size.height - appendixSize.height); - path.arcToPoint( - Offset(0, size.height - appendixSize.height - radius), - radius: circularRadius, - ); - path.lineTo(0, 0); - path.close(); + 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.lineTo(size.width, size.height - Dimens.borderRadiusL); + path.arcToPoint( + Offset(size.width - Dimens.borderRadiusL, size.height), + radius: circularRadius, + ); + path.lineTo(size.width - appendixSize.width + Dimens.borderRadiusL, size.height); + path.arcToPoint( + Offset(size.width - appendixSize.width, size.height - Dimens.borderRadiusL), + radius: circularRadius, + ); + path.lineTo(size.width - appendixSize.width, size.height - appendixSize.height + Dimens.borderRadiusM); + path.arcToPoint( + Offset(size.width - appendixSize.width - Dimens.borderRadiusM, size.height - appendixSize.height), + radius: circularRadius, + clockwise: false, + ); + path.lineTo(Dimens.borderRadiusL, size.height - appendixSize.height); + + path.arcToPoint( + Offset(0, size.height - appendixSize.height - Dimens.borderRadiusL), + radius: circularRadius, + ); + path.lineTo(0, 0); + path.close(); + } canvas.drawPath(path, paint); }