From 42efd4feab6fcbb5de467eba298eec36882f131f Mon Sep 17 00:00:00 2001 From: solid-oleksandrhordiienko Date: Thu, 29 Sep 2022 15:03:24 +0300 Subject: [PATCH 1/3] Replace rotation from RotatedBox tu chevronPainter --- .../components/buttons/rounded_button.dart | 2 +- lib/src/components/chevron.dart | 39 +++++++++++-------- .../horizontal_help_widget.dart | 4 +- .../help_collection/square_help_widget.dart | 2 +- .../links_card_widget/links_card_button.dart | 6 +-- 5 files changed, 30 insertions(+), 23 deletions(-) diff --git a/lib/src/components/buttons/rounded_button.dart b/lib/src/components/buttons/rounded_button.dart index 28e7bbe..7f974bb 100644 --- a/lib/src/components/buttons/rounded_button.dart +++ b/lib/src/components/buttons/rounded_button.dart @@ -36,7 +36,7 @@ class _RoundedButtonState extends State { static const _additionalSpace = 1.0; - static const _defaultChevronOffset = Offset(4, 2); + static const _defaultChevronOffset = Offset(3.0, 9); @override Widget build(BuildContext context) { diff --git a/lib/src/components/chevron.dart b/lib/src/components/chevron.dart index 18743ea..9908708 100644 --- a/lib/src/components/chevron.dart +++ b/lib/src/components/chevron.dart @@ -25,26 +25,27 @@ class Chevron extends StatelessWidget { @override Widget build(BuildContext context) { - return RotatedBox( - quarterTurns: _quartedTurnsForDirection(direction), - child: CustomPaint( - size: size, - painter: _CrossPainter( - color: color, - lineWidth: lineWidth, - ), + return CustomPaint( + size: size, + painter: _ChevronPainter( + color: color, + lineWidth: lineWidth, + radians: _getRadiansForDirection(direction), ), ); } - int _quartedTurnsForDirection(ChevronDirection direction) { - return const { - ChevronDirection.down: 0, - ChevronDirection.left: 1, - ChevronDirection.up: 2, - ChevronDirection.right: 3, + double _getRadiansForDirection(ChevronDirection direction) { + const double _pi = 3.1415; + const double _halfOfPi = _pi / 2; + + return { + ChevronDirection.down: 0.0, + ChevronDirection.left: _halfOfPi, + ChevronDirection.up: _pi, + ChevronDirection.right: -_halfOfPi, }[direction] ?? - 0; + 0.0; } } @@ -63,14 +64,16 @@ enum ChevronDirection { left } -class _CrossPainter extends CustomPainter { +class _ChevronPainter extends CustomPainter { final double lineWidth; final Color color; + final double radians; /// constructor - _CrossPainter({ + _ChevronPainter({ required this.color, required this.lineWidth, + required this.radians, }); @override @@ -87,6 +90,8 @@ class _CrossPainter extends CustomPainter { final x = halfLine / 2; + canvas.rotate(radians); + canvas.drawLine( Offset.zero, Offset(halfWidth + x, halfHeight + x), diff --git a/lib/src/widgets/help_collection/horizontal_help_widget.dart b/lib/src/widgets/help_collection/horizontal_help_widget.dart index d3e2184..b48cc35 100644 --- a/lib/src/widgets/help_collection/horizontal_help_widget.dart +++ b/lib/src/widgets/help_collection/horizontal_help_widget.dart @@ -28,6 +28,7 @@ class HorizontalHelpWidget extends StatelessWidget { // It's fontSize for "Hide" button in options static const _hideButtonFontSize = 19.2; + static const _additionalSpacing = 14.0; static const _optionsFontSize = 20.8; static const _optionHeight = 51.19; static const _outerHorizontalPadding = 25.6; @@ -62,7 +63,8 @@ class HorizontalHelpWidget extends StatelessWidget { onClose: _controller.goBack, hideButtonFontSize: _hideButtonFontSize, chevronSize: const Size.square(9), - chevronPadding: const EdgeInsets.only(left: 6, bottom: 3.5), + chevronPadding: const EdgeInsets.only(left: 15, top: 13.5), + additionalSpacing: _additionalSpacing, ), ), ), diff --git a/lib/src/widgets/help_collection/square_help_widget.dart b/lib/src/widgets/help_collection/square_help_widget.dart index 77ded9a..038b3dd 100644 --- a/lib/src/widgets/help_collection/square_help_widget.dart +++ b/lib/src/widgets/help_collection/square_help_widget.dart @@ -31,7 +31,7 @@ class SquareHelpWidget extends StatelessWidget { static const _optionsWidth = 246.39; static const _lineWidth = 2.0; static const _chevronSize = 5.625; - static const _chevronOffset = Offset(-1.5, 0); + static const _chevronOffset = Offset(4.5, 0); /// Constructor SquareHelpWidget({ diff --git a/lib/src/widgets/links_card_widget/links_card_button.dart b/lib/src/widgets/links_card_widget/links_card_button.dart index 0854885..789ed2b 100644 --- a/lib/src/widgets/links_card_widget/links_card_button.dart +++ b/lib/src/widgets/links_card_widget/links_card_button.dart @@ -38,10 +38,10 @@ class _LinksCardButtonState extends State { static const _defaultFontSize = 16.64; static const _defaultChevronPadding = EdgeInsets.only( - left: 7, - bottom: 2.5, + left: 13.0, + top: 10.0, ); - static const double _defaultAdditionalSpacing = 4.0; + static const double _defaultAdditionalSpacing = 10.0; void _onHoverChanged(bool value) { setState(() { From 35aaedb8f0b9972a0e5012b5c2aab9cd765b89d5 Mon Sep 17 00:00:00 2001 From: solid-oleksandrhordiienko Date: Thu, 29 Sep 2022 15:26:36 +0300 Subject: [PATCH 2/3] fix --- lib/src/components/chevron.dart | 34 ++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/src/components/chevron.dart b/lib/src/components/chevron.dart index 9908708..8ab2ffb 100644 --- a/lib/src/components/chevron.dart +++ b/lib/src/components/chevron.dart @@ -30,23 +30,10 @@ class Chevron extends StatelessWidget { painter: _ChevronPainter( color: color, lineWidth: lineWidth, - radians: _getRadiansForDirection(direction), + direction: direction, ), ); } - - double _getRadiansForDirection(ChevronDirection direction) { - const double _pi = 3.1415; - const double _halfOfPi = _pi / 2; - - return { - ChevronDirection.down: 0.0, - ChevronDirection.left: _halfOfPi, - ChevronDirection.up: _pi, - ChevronDirection.right: -_halfOfPi, - }[direction] ?? - 0.0; - } } /// The direction where the chevron arrow will be pointing. @@ -67,15 +54,28 @@ enum ChevronDirection { class _ChevronPainter extends CustomPainter { final double lineWidth; final Color color; - final double radians; + final ChevronDirection direction; /// constructor _ChevronPainter({ required this.color, required this.lineWidth, - required this.radians, + required this.direction, }); + double _getRadiansForDirection(ChevronDirection direction) { + const double _pi = 3.1415; + const double _halfOfPi = _pi / 2; + + return { + ChevronDirection.down: 0.0, + ChevronDirection.left: _halfOfPi, + ChevronDirection.up: _pi, + ChevronDirection.right: -_halfOfPi, + }[direction] ?? + 0.0; + } + @override void paint(Canvas canvas, Size size) { final paint = Paint() @@ -90,7 +90,7 @@ class _ChevronPainter extends CustomPainter { final x = halfLine / 2; - canvas.rotate(radians); + canvas.rotate(_getRadiansForDirection(direction)); canvas.drawLine( Offset.zero, From f591f27548a65726dc3f58e8b23ff8f318cb6323 Mon Sep 17 00:00:00 2001 From: solid-oleksandrhordiienko Date: Thu, 29 Sep 2022 15:32:05 +0300 Subject: [PATCH 3/3] add switch case --- lib/src/components/chevron.dart | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/src/components/chevron.dart b/lib/src/components/chevron.dart index 8ab2ffb..c4472ac 100644 --- a/lib/src/components/chevron.dart +++ b/lib/src/components/chevron.dart @@ -54,26 +54,31 @@ enum ChevronDirection { class _ChevronPainter extends CustomPainter { final double lineWidth; final Color color; - final ChevronDirection direction; + final ChevronDirection? direction; /// constructor _ChevronPainter({ required this.color, required this.lineWidth, - required this.direction, + this.direction, }); - double _getRadiansForDirection(ChevronDirection direction) { + double _getRadiansForDirection(ChevronDirection? direction) { const double _pi = 3.1415; const double _halfOfPi = _pi / 2; - return { - ChevronDirection.down: 0.0, - ChevronDirection.left: _halfOfPi, - ChevronDirection.up: _pi, - ChevronDirection.right: -_halfOfPi, - }[direction] ?? - 0.0; + switch (direction) { + case ChevronDirection.down: + return 0.0; + case ChevronDirection.left: + return _halfOfPi; + case ChevronDirection.up: + return _pi; + case ChevronDirection.right: + return -_halfOfPi; + default: + return 0.0; + } } @override