@@ -151,14 +151,13 @@ class _MessageTile extends StatelessWidget {
151151 child: Column (
152152 crossAxisAlignment: CrossAxisAlignment .start,
153153 children: [
154- Text (
155- message.content.isEmpty && message.isStreaming
156- ? '▌'
157- : message.content,
158- style : TextStyle (
159- color : isUser ? cs.onPrimaryContainer : cs.onSurface,
154+ if (message.content.isEmpty && message.isStreaming)
155+ Text ( '▌' , style : TextStyle (color : cs.onSurface))
156+ else
157+ _StyledMessageContent (
158+ content : message.content,
159+ baseColor : isUser ? cs.onPrimaryContainer : cs.onSurface,
160160 ),
161- ),
162161 if (message.isStreaming && message.content.isNotEmpty)
163162 const Padding (
164163 padding: EdgeInsets .only (top: 4 ),
@@ -185,6 +184,54 @@ class _MessageTile extends StatelessWidget {
185184 }
186185}
187186
187+ // 將 [CRITICAL]/[ALERT]/[WARNING]/[OK] 轉為 icon + 文字行
188+ class _StyledMessageContent extends StatelessWidget {
189+ final String content;
190+ final Color baseColor;
191+
192+ const _StyledMessageContent ({required this .content, required this .baseColor});
193+
194+ static const _kTags = {
195+ '[CRITICAL]' : (Icons .error, Colors .red),
196+ '[ALERT]' : (Icons .warning_rounded, Colors .orange),
197+ '[WARNING]' : (Icons .warning_amber_outlined, Colors .amber),
198+ '[OK]' : (Icons .check_circle_outline, Colors .green),
199+ };
200+
201+ @override
202+ Widget build (BuildContext context) {
203+ final lines = content.split ('\n ' );
204+ return Column (
205+ crossAxisAlignment: CrossAxisAlignment .start,
206+ children: lines.map ((line) {
207+ for (final entry in _kTags.entries) {
208+ if (line.startsWith (entry.key)) {
209+ final (icon, color) = entry.value;
210+ final rest = line.substring (entry.key.length).trimLeft ();
211+ return Padding (
212+ padding: const EdgeInsets .only (top: 4 ),
213+ child: Row (
214+ crossAxisAlignment: CrossAxisAlignment .start,
215+ children: [
216+ Icon (icon, size: 16 , color: color),
217+ const SizedBox (width: 4 ),
218+ Expanded (
219+ child: Text (
220+ rest,
221+ style: TextStyle (color: baseColor, fontWeight: FontWeight .w600),
222+ ),
223+ ),
224+ ],
225+ ),
226+ );
227+ }
228+ }
229+ return Text (line, style: TextStyle (color: baseColor));
230+ }).toList (),
231+ );
232+ }
233+ }
234+
188235// ── 快捷測試題按鈕 ────────────────────────────────────────
189236
190237enum _ChipGroup { dynamic_, static_, blocked }
0 commit comments