Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions lib/src/components/chevron.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()
Expand All @@ -90,7 +90,7 @@ class _ChevronPainter extends CustomPainter {

final x = halfLine / 2;

canvas.rotate(radians);
canvas.rotate(_getRadiansForDirection(direction));

canvas.drawLine(
Offset.zero,
Expand Down