indent_widget.dart
971 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import 'package:flutter/material.dart';
class IndentWidget extends StatelessWidget {
const IndentWidget({
super.key,
required this.child,
required this.direction,
required this.color,
});
final Widget child;
final TextDirection direction;
final Color color;
@override
Widget build(BuildContext context) {
return CustomPaint(
foregroundPainter: IndentPainter(color, direction),
child: child,
);
}
}
class IndentPainter extends CustomPainter {
IndentPainter(this.color, this.direction);
final Color color;
final TextDirection direction;
@override
void paint(Canvas canvas, Size size) {
var left = direction == TextDirection.ltr;
var start = left ? 0.0 : size.width - 4;
var rect = Rect.fromLTWH(start, 0, 4, size.height);
var paint = Paint()..color = color;
canvas.drawRect(rect, paint);
}
@override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
return true;
}
}