Matthias Nott
3 days ago c9739ac4a22733d45167173446c1d3ce65a767eb
lib/widgets/message_bubble.dart
....@@ -14,6 +14,7 @@
1414 import '../models/message.dart';
1515 import '../theme/app_theme.dart';
1616 import 'image_viewer.dart';
17
+import 'pdf_viewer.dart';
1718
1819 // Cache decoded image bytes to prevent flicker on widget rebuild
1920 final Map<String, Uint8List> _imageCache = {};
....@@ -425,15 +426,33 @@
425426 if (data == null || data.isEmpty) return;
426427
427428 try {
428
- final bytes = base64Decode(data.contains(',') ? data.split(',').last : data);
429
+ final bytes = Uint8List.fromList(
430
+ base64Decode(data.contains(',') ? data.split(',').last : data),
431
+ );
429432 final mime = message.mimeType ?? 'application/octet-stream';
433
+
434
+ // PDFs: open inline viewer
435
+ if (mime == 'application/pdf') {
436
+ if (context.mounted) {
437
+ Navigator.of(context).push(
438
+ MaterialPageRoute(
439
+ builder: (_) => PdfViewerScreen(
440
+ pdfBytes: bytes,
441
+ title: message.content.isNotEmpty ? message.content : 'PDF',
442
+ ),
443
+ ),
444
+ );
445
+ }
446
+ return;
447
+ }
448
+
449
+ // Other files: save to temp and share
430450 final ext = _mimeToExt(mime);
431451 final dir = await getTemporaryDirectory();
432452 final fileName = '${message.content.isNotEmpty ? message.content.replaceAll(RegExp(r'[^\w\s.-]'), '').trim() : 'file'}.$ext';
433453 final file = File('${dir.path}/$fileName');
434454 await file.writeAsBytes(bytes);
435455
436
- // Use share sheet — works for PDFs, Office docs, and all file types on iOS
437456 await SharePlus.instance.share(
438457 ShareParams(files: [XFile(file.path, mimeType: mime)]),
439458 );