-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
chart_legend.dart
89 lines (83 loc) · 2.21 KB
/
chart_legend.dart
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import 'package:flutter/material.dart';
import 'package:shiori/presentation/shared/styles.dart';
class ChartLegend extends StatelessWidget {
final List<ChartLegendIndicator> indicators;
const ChartLegend({
super.key,
required this.indicators,
});
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.start,
children: indicators,
);
}
}
class ChartLegendIndicator extends StatelessWidget {
final Color color;
final String text;
final double size;
final VoidCallback? tap;
final bool expandText;
final bool selected;
final double? width;
const ChartLegendIndicator({
super.key,
required this.color,
required this.text,
this.size = 16,
this.tap,
this.expandText = true,
this.selected = false,
this.width,
});
@override
Widget build(BuildContext context) {
final textStyle = TextStyle(
fontSize: size,
fontWeight: FontWeight.bold,
color: Colors.grey,
decorationThickness: 3,
);
return Container(
margin: expandText ? const EdgeInsets.symmetric(vertical: 3) : Styles.edgeInsetAll5,
width: width,
child: Tooltip(
message: text,
child: InkWell(
onTap: tap != null ? () => tap?.call() : null,
child: Row(
children: [
Container(
width: size,
height: size,
decoration: BoxDecoration(
color: color,
borderRadius: BorderRadius.circular(5),
),
child: selected ? Icon(Icons.check_circle_outline, size: size / 1.2) : null,
),
const SizedBox(width: 4),
if (expandText)
Expanded(
child: Text(
text,
overflow: TextOverflow.ellipsis,
style: textStyle,
),
)
else
Text(
text,
overflow: TextOverflow.ellipsis,
style: textStyle,
)
],
),
),
),
);
}
}