[SYNC]
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
class GradientBoxBorder extends Border {
|
||||
const GradientBoxBorder({required this.gradient, this.width = 1.0, super.bottom, super.left, super.right, super.top});
|
||||
|
||||
final Gradient gradient;
|
||||
|
||||
final double width;
|
||||
|
||||
@override
|
||||
EdgeInsetsGeometry get dimensions => EdgeInsets.all(width);
|
||||
|
||||
@override
|
||||
void paint(
|
||||
Canvas canvas,
|
||||
Rect rect, {
|
||||
TextDirection? textDirection,
|
||||
BoxShape shape = BoxShape.rectangle,
|
||||
BorderRadius? borderRadius,
|
||||
}) {
|
||||
switch (shape) {
|
||||
case BoxShape.circle:
|
||||
assert(
|
||||
borderRadius == null,
|
||||
'A borderRadius can only be given for rectangular boxes.',
|
||||
);
|
||||
_paintCircle(canvas, rect);
|
||||
break;
|
||||
case BoxShape.rectangle:
|
||||
if (borderRadius != null) {
|
||||
_paintRRect(canvas, rect, borderRadius);
|
||||
return;
|
||||
}
|
||||
_paintRect(canvas, rect);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void _paintRect(Canvas canvas, Rect rect) {
|
||||
// canvas.drawRect(rect.deflate(width / 2), _getPaint(rect));
|
||||
canvas.drawLine(rect.bottomLeft, rect.bottomRight, _getPaint(rect));
|
||||
}
|
||||
|
||||
void _paintRRect(Canvas canvas, Rect rect, BorderRadius borderRadius) {
|
||||
// final rrect = borderRadius.toRRect().deflate(width / 2);
|
||||
|
||||
canvas.drawLine(rect.bottomLeft, rect.bottomRight, _getPaint(rect));
|
||||
}
|
||||
|
||||
void _paintCircle(Canvas canvas, Rect rect) {
|
||||
final paint = _getPaint(rect);
|
||||
final radius = (rect.shortestSide - width) / 2.0;
|
||||
canvas.drawCircle(rect.center, radius, paint);
|
||||
}
|
||||
|
||||
@override
|
||||
Border scale(double t) {
|
||||
return this;
|
||||
}
|
||||
|
||||
Paint _getPaint(Rect rect) {
|
||||
return Paint()
|
||||
..strokeWidth = width
|
||||
..shader = gradient.createShader(rect)
|
||||
..style = PaintingStyle.stroke;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user