Matthias Nott
2026-07-08 77911f6418ceb771c5f0b6b2aa33328c7aa5530a
lib/widgets/message_bubble.dart
....@@ -63,8 +63,8 @@
6363 color: _isUser
6464 ? (isDark ? AppColors.userBubble : AppColors.lightUserBubble)
6565 : (isDark
66
- ? AppColors.assistantBubble
67
- : AppColors.lightAssistantBubble),
66
+ ? AppColors.assistantBubble
67
+ : AppColors.lightAssistantBubble),
6868 borderRadius: BorderRadius.only(
6969 topLeft: const Radius.circular(16),
7070 topRight: const Radius.circular(16),
....@@ -138,44 +138,60 @@
138138 ? Colors.white.withAlpha(20)
139139 : Colors.black.withAlpha(15);
140140
141
- return MarkdownBody(
142
- data: message.content,
143
- selectable: true,
144
- softLineBreak: true,
145
- styleSheet: MarkdownStyleSheet(
146
- p: TextStyle(fontSize: 15, height: 1.4, color: textColor),
147
- h1: TextStyle(fontSize: 20, fontWeight: FontWeight.bold, color: textColor),
148
- h2: TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: textColor),
149
- h3: TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: textColor),
150
- strong: TextStyle(fontWeight: FontWeight.bold, color: textColor),
151
- em: TextStyle(fontStyle: FontStyle.italic, color: textColor),
152
- code: TextStyle(
153
- fontSize: 13,
154
- fontFamily: 'monospace',
155
- color: textColor,
156
- backgroundColor: codeBackground,
157
- ),
158
- codeblockDecoration: BoxDecoration(
159
- color: codeBackground,
160
- borderRadius: BorderRadius.circular(8),
161
- ),
162
- codeblockPadding: const EdgeInsets.all(10),
163
- listBullet: TextStyle(fontSize: 15, color: textColor),
164
- blockquoteDecoration: BoxDecoration(
165
- border: Border(
166
- left: BorderSide(color: AppColors.accent, width: 3),
141
+ // SelectionArea gives one continuous selection across all markdown blocks
142
+ // (paragraphs, lists, code). MarkdownBody's own `selectable: true` makes each
143
+ // block a separate SelectableText, which is why dragging snapped paragraph
144
+ // by paragraph — so it's disabled here in favour of the SelectionArea.
145
+ return SelectionArea(
146
+ child: MarkdownBody(
147
+ data: message.content,
148
+ selectable: false,
149
+ softLineBreak: true,
150
+ styleSheet: MarkdownStyleSheet(
151
+ p: TextStyle(fontSize: 15, height: 1.4, color: textColor),
152
+ h1: TextStyle(
153
+ fontSize: 20,
154
+ fontWeight: FontWeight.bold,
155
+ color: textColor,
167156 ),
157
+ h2: TextStyle(
158
+ fontSize: 18,
159
+ fontWeight: FontWeight.bold,
160
+ color: textColor,
161
+ ),
162
+ h3: TextStyle(
163
+ fontSize: 16,
164
+ fontWeight: FontWeight.bold,
165
+ color: textColor,
166
+ ),
167
+ strong: TextStyle(fontWeight: FontWeight.bold, color: textColor),
168
+ em: TextStyle(fontStyle: FontStyle.italic, color: textColor),
169
+ code: TextStyle(
170
+ fontSize: 13,
171
+ fontFamily: 'monospace',
172
+ color: textColor,
173
+ backgroundColor: codeBackground,
174
+ ),
175
+ codeblockDecoration: BoxDecoration(
176
+ color: codeBackground,
177
+ borderRadius: BorderRadius.circular(8),
178
+ ),
179
+ codeblockPadding: const EdgeInsets.all(10),
180
+ listBullet: TextStyle(fontSize: 15, color: textColor),
181
+ blockquoteDecoration: BoxDecoration(
182
+ border: Border(left: BorderSide(color: AppColors.accent, width: 3)),
183
+ ),
184
+ blockquotePadding: const EdgeInsets.only(left: 12, top: 4, bottom: 4),
168185 ),
169
- blockquotePadding: const EdgeInsets.only(left: 12, top: 4, bottom: 4),
170
- ),
171
- onTapLink: (text, href, title) {
172
- if (href != null) {
173
- final uri = Uri.tryParse(href);
174
- if (uri != null) {
175
- launchUrl(uri, mode: LaunchMode.externalApplication);
186
+ onTapLink: (text, href, title) {
187
+ if (href != null) {
188
+ final uri = Uri.tryParse(href);
189
+ if (uri != null) {
190
+ launchUrl(uri, mode: LaunchMode.externalApplication);
191
+ }
176192 }
177
- }
178
- },
193
+ },
194
+ ),
179195 );
180196 }
181197
....@@ -224,8 +240,8 @@
224240 color: _isUser
225241 ? Colors.white.withAlpha(180)
226242 : (isDark
227
- ? AppColors.darkTextSecondary
228
- : AppColors.lightTextSecondary),
243
+ ? AppColors.darkTextSecondary
244
+ : AppColors.lightTextSecondary),
229245 borderRadius: BorderRadius.circular(2),
230246 ),
231247 );
....@@ -242,8 +258,8 @@
242258 color: _isUser
243259 ? Colors.white70
244260 : (isDark
245
- ? AppColors.darkTextTertiary
246
- : AppColors.lightTextSecondary),
261
+ ? AppColors.darkTextTertiary
262
+ : AppColors.lightTextSecondary),
247263 ),
248264 ),
249265 ],
....@@ -289,9 +305,9 @@
289305 _imageCache.remove(_imageCache.keys.first);
290306 }
291307 final raw = message.imageBase64!;
292
- _imageCache[message.id] = Uint8List.fromList(base64Decode(
293
- raw.contains(',') ? raw.split(',').last : raw,
294
- ));
308
+ _imageCache[message.id] = Uint8List.fromList(
309
+ base64Decode(raw.contains(',') ? raw.split(',').last : raw),
310
+ );
295311 }
296312 final bytes = _imageCache[message.id]!;
297313
....@@ -301,9 +317,7 @@
301317 GestureDetector(
302318 onTap: () {
303319 Navigator.of(context).push(
304
- MaterialPageRoute(
305
- builder: (_) => ImageViewer(imageBytes: bytes),
306
- ),
320
+ MaterialPageRoute(builder: (_) => ImageViewer(imageBytes: bytes)),
307321 );
308322 },
309323 child: ClipRRect(
....@@ -348,7 +362,9 @@
348362 if (isPdf) {
349363 icon = Icons.picture_as_pdf;
350364 iconColor = Colors.red;
351
- } else if (mime.contains('spreadsheet') || mime.contains('excel') || mime == 'text/csv') {
365
+ } else if (mime.contains('spreadsheet') ||
366
+ mime.contains('excel') ||
367
+ mime == 'text/csv') {
352368 icon = Icons.table_chart;
353369 iconColor = Colors.green;
354370 } else if (mime.contains('word') || mime.contains('document')) {
....@@ -370,7 +386,9 @@
370386 width: 260,
371387 padding: const EdgeInsets.all(12),
372388 decoration: BoxDecoration(
373
- color: (_isUser ? Colors.white : Theme.of(context).colorScheme.primary).withAlpha(25),
389
+ color:
390
+ (_isUser ? Colors.white : Theme.of(context).colorScheme.primary)
391
+ .withAlpha(25),
374392 borderRadius: BorderRadius.circular(8),
375393 border: Border.all(
376394 color: (_isUser ? Colors.white : Colors.grey).withAlpha(50),
....@@ -402,7 +420,8 @@
402420 '${mime.split('/').last.toUpperCase()} - ${sizeKB} KB',
403421 style: TextStyle(
404422 fontSize: 11,
405
- color: (_isUser ? Colors.white : Colors.grey).withAlpha(180),
423
+ color: (_isUser ? Colors.white : Colors.grey)
424
+ .withAlpha(180),
406425 ),
407426 ),
408427 ],
....@@ -449,7 +468,8 @@
449468 // Other files: save to temp and share
450469 final ext = _mimeToExt(mime);
451470 final dir = await getTemporaryDirectory();
452
- final fileName = '${message.content.isNotEmpty ? message.content.replaceAll(RegExp(r'[^\w\s.-]'), '').trim() : 'file'}.$ext';
471
+ final fileName =
472
+ '${message.content.isNotEmpty ? message.content.replaceAll(RegExp(r'[^\w\s.-]'), '').trim() : 'file'}.$ext';
453473 final file = File('${dir.path}/$fileName');
454474 await file.writeAsBytes(bytes);
455475
....@@ -458,9 +478,9 @@
458478 );
459479 } catch (e) {
460480 if (context.mounted) {
461
- ScaffoldMessenger.of(context).showSnackBar(
462
- SnackBar(content: Text('Could not open file: $e')),
463
- );
481
+ ScaffoldMessenger.of(
482
+ context,
483
+ ).showSnackBar(SnackBar(content: Text('Could not open file: $e')));
464484 }
465485 }
466486 }
....@@ -469,9 +489,11 @@
469489 const map = {
470490 'application/pdf': 'pdf',
471491 'application/msword': 'doc',
472
- 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 'docx',
492
+ 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
493
+ 'docx',
473494 'application/vnd.ms-excel': 'xls',
474
- 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': 'xlsx',
495
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
496
+ 'xlsx',
475497 'text/plain': 'txt',
476498 'text/csv': 'csv',
477499 'text/markdown': 'md',
....@@ -499,9 +521,7 @@
499521 fontSize: 11,
500522 color: _isUser
501523 ? Colors.white60
502
- : (isDark
503
- ? AppColors.darkTextTertiary
504
- : Colors.grey.shade500),
524
+ : (isDark ? AppColors.darkTextTertiary : Colors.grey.shade500),
505525 ),
506526 ),
507527 if (message.status == MessageStatus.sending) ...[
....@@ -546,8 +566,14 @@
546566 ),
547567 if (onDelete != null)
548568 ListTile(
549
- leading: const Icon(Icons.delete_outline, color: AppColors.error),
550
- title: const Text('Delete', style: TextStyle(color: AppColors.error)),
569
+ leading: const Icon(
570
+ Icons.delete_outline,
571
+ color: AppColors.error,
572
+ ),
573
+ title: const Text(
574
+ 'Delete',
575
+ style: TextStyle(color: AppColors.error),
576
+ ),
551577 onTap: () {
552578 Navigator.pop(ctx);
553579 onDelete?.call();