@@ -13,45 +13,53 @@ enum FontStyle {
1313}
1414
1515/// The thickness of the glyphs used to draw the text
16- enum FontWeight {
16+ class FontWeight {
17+ const FontWeight ._(this .index, this .value);
18+
19+ /// The encoded integer value of this font weight.
20+ final int index;
21+
22+ /// The thickness value of this font weight.
23+ final int value;
24+
1725 /// Thin, the least thick
18- w100._(100 ),
26+ static const FontWeight w100 = FontWeight ._(0 , 100 );
1927
2028 /// Extra-light
21- w200._(200 ),
29+ static const FontWeight w200 = FontWeight ._(1 , 200 );
2230
2331 /// Light
24- w300._(300 ),
32+ static const FontWeight w300 = FontWeight ._(2 , 300 );
2533
2634 /// Normal / regular / plain
27- w400._(400 ),
35+ static const FontWeight w400 = FontWeight ._(3 , 400 );
2836
2937 /// Medium
30- w500._(500 ),
38+ static const FontWeight w500 = FontWeight ._(4 , 500 );
3139
3240 /// Semi-bold
33- w600._(600 ),
41+ static const FontWeight w600 = FontWeight ._(5 , 600 );
3442
3543 /// Bold
36- w700._(700 ),
44+ static const FontWeight w700 = FontWeight ._(6 , 700 );
3745
3846 /// Extra-bold
39- w800._(800 ),
47+ static const FontWeight w800 = FontWeight ._(7 , 800 );
4048
4149 /// Black, the most thick
42- w900._(900 );
43-
44- const FontWeight ._(this .value);
45-
46- /// The thickness value of this font weight.
47- final int value;
50+ static const FontWeight w900 = FontWeight ._(8 , 900 );
4851
4952 /// The default font weight.
5053 static const FontWeight normal = w400;
5154
5255 /// A commonly used font weight that is heavier than normal.
5356 static const FontWeight bold = w700;
5457
58+ /// A list of all the font weights.
59+ static const List <FontWeight > values = < FontWeight > [
60+ w100, w200, w300, w400, w500, w600, w700, w800, w900
61+ ];
62+
5563 /// Linearly interpolates between two font weights.
5664 ///
5765 /// Rather than using fractional weights, the interpolation rounds to the
@@ -79,6 +87,21 @@ enum FontWeight {
7987 }
8088 return values[_lerpInt ((a ?? normal).index, (b ?? normal).index, t).round ().clamp (0 , 8 )];
8189 }
90+
91+ @override
92+ String toString () {
93+ return const < int , String > {
94+ 0 : 'FontWeight.w100' ,
95+ 1 : 'FontWeight.w200' ,
96+ 2 : 'FontWeight.w300' ,
97+ 3 : 'FontWeight.w400' ,
98+ 4 : 'FontWeight.w500' ,
99+ 5 : 'FontWeight.w600' ,
100+ 6 : 'FontWeight.w700' ,
101+ 7 : 'FontWeight.w800' ,
102+ 8 : 'FontWeight.w900' ,
103+ }[index]! ;
104+ }
82105}
83106
84107/// A feature tag and value that affect the selection of glyphs in a font.
0 commit comments