@@ -63,12 +63,44 @@ class LeadingChip extends ChipWidget {
63
63
64
64
/// A rectangular chip to match the style of the swift version of the forum.
65
65
class RectangularChip extends ChipWidget {
66
- const RectangularChip ({super .key, super .label, super .onTap, super .color});
66
+ /// Is the chip highlighted?
67
+ ///
68
+ /// If true, the chip will have a gradient background and [color] will be ignored.
69
+ final bool highlighted;
70
+
71
+ const RectangularChip ({super .key, super .label, super .onTap, super .color, this .highlighted = false });
67
72
68
73
@override
69
74
Widget build (BuildContext context) {
70
75
final effectiveColor = color ?? Theme .of (context).colorScheme.primary;
71
76
final lightness = HSLColor .fromColor (effectiveColor).lightness;
77
+ BoxDecoration backgroundDecor;
78
+ Color textColor;
79
+ if (highlighted) {
80
+ backgroundDecor = BoxDecoration (
81
+ gradient: LinearGradient (
82
+ colors: [
83
+ Colors .blue.withValues (alpha: 0.9 ),
84
+ Colors .purple.withValues (alpha: 0.9 ),
85
+ ],
86
+ begin: Alignment .topLeft,
87
+ end: Alignment .bottomRight,
88
+ ),
89
+ borderRadius: BorderRadius .circular (2 ),
90
+ );
91
+ textColor = Colors .white;
92
+ } else {
93
+ backgroundDecor = BoxDecoration (
94
+ color: effectiveColor.withValues (alpha: 0.3 ),
95
+ borderRadius: BorderRadius .circular (2 ),
96
+ );
97
+ // Make text brighter under dark mode, and darker under light mode
98
+ textColor = PlatformX .isDarkMode
99
+ ? effectiveColor
100
+ .withLightness ((lightness + 0.2 ).clamp (0 , 1 ))
101
+ : effectiveColor
102
+ .withLightness ((lightness - 0.2 ).clamp (0 , 1 ));
103
+ }
72
104
return Row (
73
105
mainAxisSize: MainAxisSize .min,
74
106
children: [
@@ -77,22 +109,15 @@ class RectangularChip extends ChipWidget {
77
109
onTap: onTap,
78
110
child: Container (
79
111
padding: const EdgeInsets .symmetric (horizontal: 4 , vertical: 1 ),
80
- decoration: BoxDecoration (
81
- color: effectiveColor.withValues (alpha: 0.3 ),
82
- borderRadius: BorderRadius .circular (2 ),
83
- ),
112
+ decoration: backgroundDecor,
84
113
child: Center (
85
114
child: Text (
86
115
label ?? "" ,
87
116
style: TextStyle (
88
117
fontSize: 12 ,
89
118
leadingDistribution: TextLeadingDistribution .even,
90
- // Make text brighter under dark mode, and darker under light mode
91
- color: PlatformX .isDarkMode
92
- ? effectiveColor
93
- .withLightness ((lightness + 0.2 ).clamp (0 , 1 ))
94
- : effectiveColor
95
- .withLightness ((lightness - 0.2 ).clamp (0 , 1 )),
119
+
120
+ color: textColor,
96
121
),
97
122
),
98
123
),
0 commit comments