| .. | .. |
|---|
| 14 | 14 | import '../models/message.dart'; |
|---|
| 15 | 15 | import '../theme/app_theme.dart'; |
|---|
| 16 | 16 | import 'image_viewer.dart'; |
|---|
| 17 | +import 'pdf_viewer.dart'; |
|---|
| 17 | 18 | |
|---|
| 18 | 19 | // Cache decoded image bytes to prevent flicker on widget rebuild |
|---|
| 19 | 20 | final Map<String, Uint8List> _imageCache = {}; |
|---|
| .. | .. |
|---|
| 425 | 426 | if (data == null || data.isEmpty) return; |
|---|
| 426 | 427 | |
|---|
| 427 | 428 | 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 | + ); |
|---|
| 429 | 432 | 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 |
|---|
| 430 | 450 | final ext = _mimeToExt(mime); |
|---|
| 431 | 451 | final dir = await getTemporaryDirectory(); |
|---|
| 432 | 452 | final fileName = '${message.content.isNotEmpty ? message.content.replaceAll(RegExp(r'[^\w\s.-]'), '').trim() : 'file'}.$ext'; |
|---|
| 433 | 453 | final file = File('${dir.path}/$fileName'); |
|---|
| 434 | 454 | await file.writeAsBytes(bytes); |
|---|
| 435 | 455 | |
|---|
| 436 | | - // Use share sheet — works for PDFs, Office docs, and all file types on iOS |
|---|
| 437 | 456 | await SharePlus.instance.share( |
|---|
| 438 | 457 | ShareParams(files: [XFile(file.path, mimeType: mime)]), |
|---|
| 439 | 458 | ); |
|---|