@@ -17,90 +17,84 @@ class IntensityLegend extends StatelessWidget {
1717
1818 List <Color > get _colors => mode == IntensityLegendMode .eew
1919 ? List .generate (9 , (i) => IntensityColor .intensity (i + 1 ))
20- : List .generate (11 , (i) => InstrumentalIntensityColor .intensity (i - 3 ));
20+ : List .generate (11 , (i) => InstrumentalIntensityColor .intensity (7 - i ));
2121
2222 List <String > get _labels => mode == IntensityLegendMode .eew
2323 ? const ['1' , '2' , '3' , '4' , '5⁻' , '5⁺' , '6⁻' , '6⁺' , '7' ]
2424 : const ['-3' , '-2' , '-1' , '0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' ];
2525
2626 @override
2727 Widget build (BuildContext context) {
28- final screenWidth = MediaQuery .of (context).size.width;
29- final width = screenWidth / 2 ;
30-
31- return SizedBox (
32- width: width,
33- child: Column (
34- mainAxisSize: MainAxisSize .min,
35- crossAxisAlignment: CrossAxisAlignment .end,
36- children: [
37- _buildColorBar (width),
38- const SizedBox (height: 2 ),
39- _buildLabels (width),
40- ],
41- ),
28+ return Column (
29+ mainAxisSize: MainAxisSize .min,
30+ crossAxisAlignment: CrossAxisAlignment .start,
31+ children: _buildLegendItems (),
4232 );
4333 }
4434
45- Widget _buildColorBar (double width) {
35+ List <Widget > _buildLegendItems () {
36+ final colors = mode == IntensityLegendMode .eew ? _colors.reversed.toList () : _colors;
37+ final labels = _labels.reversed.toList ();
38+
4639 if (mode == IntensityLegendMode .eew) {
47- // EEW mode: discrete color blocks
48- return ClipRRect (
49- borderRadius: BorderRadius .circular (4 ),
50- child: SizedBox (
51- height: 8 ,
52- width: width,
53- child: Row (
54- children: _colors.map ((color) {
55- return Expanded (child: Container (color: color));
56- }).toList (),
57- ),
58- ),
59- );
40+ return List .generate (colors.length, (index) {
41+ return Row (
42+ mainAxisSize: MainAxisSize .min,
43+ crossAxisAlignment: CrossAxisAlignment .center,
44+ children: [
45+ Container (
46+ height: 12 ,
47+ width: 16 ,
48+ color: colors[index],
49+ ),
50+ const SizedBox (width: 6 ),
51+ Text (
52+ labels[index],
53+ style: const TextStyle (fontSize: 10 , height: 1 ),
54+ ),
55+ ],
56+ );
57+ });
6058 } else {
61- // RTS mode: gradient
62- return Container (
63- height: 8 ,
64- width: width,
65- decoration: BoxDecoration (
66- borderRadius: BorderRadius .circular (4 ),
67- gradient: LinearGradient (colors: _colors),
68- ),
69- );
70- }
71- }
59+ final labelWidgets = labels.map ((label) {
60+ return Expanded (
61+ child: Text (
62+ label,
63+ style: const TextStyle (fontSize: 9 , height: 1 ),
64+ textAlign: TextAlign .left,
65+ ),
66+ );
67+ }).toList ();
7268
73- Widget _buildLabels (double width) {
74- if (mode == IntensityLegendMode .eew) {
75- // EEW mode: labels centered under each color block
76- return SizedBox (
77- width: width,
78- child: Row (
79- children: _labels.map ((label) {
80- return Expanded (
81- child: Text (
82- label,
83- style: const TextStyle (fontSize: 9 ),
84- textAlign: TextAlign .center,
69+ return [
70+ Row (
71+ mainAxisSize: MainAxisSize .min,
72+ crossAxisAlignment: CrossAxisAlignment .start,
73+ children: [
74+ Container (
75+ height: 12.0 * colors.length,
76+ width: 16 ,
77+ decoration: BoxDecoration (
78+ borderRadius: BorderRadius .circular (4 ),
79+ gradient: LinearGradient (
80+ colors: colors,
81+ begin: Alignment .topCenter,
82+ end: Alignment .bottomCenter,
83+ ),
8584 ),
86- );
87- }).toList (),
88- ),
89- );
90- } else {
91- // RTS mode: labels at edges
92- return SizedBox (
93- width: width,
94- child: Row (
95- mainAxisAlignment: MainAxisAlignment .spaceBetween,
96- children: _labels.map ((label) {
97- return Text (
98- label,
99- style: const TextStyle (fontSize: 9 ),
100- );
101- }).toList (),
85+ ),
86+ const SizedBox (width: 6 ),
87+ SizedBox (
88+ height: 12.0 * colors.length,
89+ child: Column (
90+ mainAxisAlignment: MainAxisAlignment .spaceEvenly,
91+ crossAxisAlignment: CrossAxisAlignment .start,
92+ children: labelWidgets,
93+ ),
94+ ),
95+ ],
10296 ),
103- ) ;
97+ ] ;
10498 }
10599 }
106100}
0 commit comments