Skip to content

Commit 433f4a3

Browse files
committed
feat: close #468
1 parent b70db93 commit 433f4a3

File tree

3 files changed

+48
-11
lines changed

3 files changed

+48
-11
lines changed

lib/repository/app/announcement_repository.dart

+8
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,14 @@ class AnnouncementRepository {
178178
.map<Celebration>((e) => parseCelebration(e))
179179
.toList();
180180
}
181+
182+
List<int> getHighlightedTagIds() {
183+
if (_tomlCache == null) {
184+
return [];
185+
}
186+
187+
return _tomlCache!['highlight_tag_ids'].cast<int>();
188+
}
181189
}
182190

183191
class UpdateInfo {

lib/widget/forum/forum_widgets.dart

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import 'package:dan_xi/model/forum/report.dart';
2424
import 'package:dan_xi/page/forum/hole_detail.dart';
2525
import 'package:dan_xi/page/subpage_forum.dart';
2626
import 'package:dan_xi/provider/settings_provider.dart';
27+
import 'package:dan_xi/repository/app/announcement_repository.dart';
2728
import 'package:dan_xi/repository/forum/forum_repository.dart';
2829
import 'package:dan_xi/util/browser_util.dart';
2930
import 'package:dan_xi/util/forum/human_duration.dart';
@@ -81,6 +82,9 @@ Widget generateTagWidgets(BuildContext context, OTHole? e,
8182
color: useAccessibilityColoring
8283
? Theme.of(context).textTheme.bodyLarge!.color
8384
: element.color,
85+
highlighted: AnnouncementRepository.getInstance()
86+
.getHighlightedTagIds()
87+
.contains(element.tag_id),
8488
));
8589
}
8690
return Wrap(

lib/widget/libraries/chip_widgets.dart

+36-11
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,44 @@ class LeadingChip extends ChipWidget {
6363

6464
/// A rectangular chip to match the style of the swift version of the forum.
6565
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});
6772

6873
@override
6974
Widget build(BuildContext context) {
7075
final effectiveColor = color ?? Theme.of(context).colorScheme.primary;
7176
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+
}
72104
return Row(
73105
mainAxisSize: MainAxisSize.min,
74106
children: [
@@ -77,22 +109,15 @@ class RectangularChip extends ChipWidget {
77109
onTap: onTap,
78110
child: Container(
79111
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,
84113
child: Center(
85114
child: Text(
86115
label ?? "",
87116
style: TextStyle(
88117
fontSize: 12,
89118
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,
96121
),
97122
),
98123
),

0 commit comments

Comments
 (0)