Frontend: restore PDF bytes loading for public viewer to fix loading, add SfTheme for app styling consistency
This commit is contained in:
@@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:web/web.dart' as web;
|
||||
import 'dart:ui_web' as ui_web;
|
||||
import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';
|
||||
import 'package:syncfusion_flutter_theme/syncfusion_flutter_theme.dart';
|
||||
import 'package:video_player/video_player.dart';
|
||||
import 'package:flutter/foundation.dart' show kIsWeb;
|
||||
import '../theme/app_theme.dart';
|
||||
@@ -25,6 +25,7 @@ class _PublicFileViewerState extends State<PublicFileViewer> {
|
||||
String? _error;
|
||||
Map<String, dynamic>? _fileData;
|
||||
VideoPlayerController? _videoController;
|
||||
List<int>? _pdfBytes;
|
||||
String? _videoViewType;
|
||||
|
||||
@override
|
||||
@@ -49,6 +50,11 @@ class _PublicFileViewerState extends State<PublicFileViewer> {
|
||||
_isLoading = false;
|
||||
});
|
||||
|
||||
// Load PDF bytes if it's a PDF file
|
||||
if (_isPdfFile()) {
|
||||
await _loadPdfBytes();
|
||||
}
|
||||
|
||||
// Initialize video player if it's a video file
|
||||
if (_isVideoFile()) {
|
||||
await _initializeVideoPlayer();
|
||||
@@ -61,7 +67,27 @@ class _PublicFileViewerState extends State<PublicFileViewer> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _initializeVideoPlayer() async {
|
||||
Future<void> _loadPdfBytes() async {
|
||||
if (_fileData?['viewUrl'] != null) {
|
||||
try {
|
||||
final apiClient = getIt<ApiClient>();
|
||||
// Extract the path from viewUrl and call it directly
|
||||
final viewUrl = _fileData!['viewUrl'] as String;
|
||||
final uri = Uri.parse(viewUrl);
|
||||
final path = uri.path + (uri.query.isNotEmpty ? '?${uri.query}' : '');
|
||||
|
||||
final bytes = await apiClient.getBytes(path);
|
||||
setState(() {
|
||||
_pdfBytes = bytes;
|
||||
});
|
||||
} catch (e) {
|
||||
// If loading fails, we'll show an error or fallback
|
||||
setState(() {
|
||||
_error = 'Failed to load PDF content.';
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!kIsWeb) {
|
||||
// For mobile, use VideoPlayerController
|
||||
final url = _fileData?['viewUrl'] ?? _fileData?['downloadUrl'];
|
||||
@@ -155,20 +181,49 @@ class _PublicFileViewerState extends State<PublicFileViewer> {
|
||||
if (viewUrl == null) return const SizedBox();
|
||||
|
||||
if (_isPdfFile()) {
|
||||
return Expanded(
|
||||
child: SfPdfViewer.network(
|
||||
viewUrl,
|
||||
onDocumentLoadFailed: (details) {
|
||||
setState(() {
|
||||
_error = 'Failed to load PDF: ${details.description}';
|
||||
});
|
||||
},
|
||||
canShowScrollHead: false,
|
||||
canShowScrollStatus: false,
|
||||
enableDoubleTapZooming: true,
|
||||
enableTextSelection: false,
|
||||
),
|
||||
);
|
||||
if (_pdfBytes != null) {
|
||||
return Expanded(
|
||||
child: SfTheme(
|
||||
data: SfThemeData(
|
||||
pdfViewerThemeData: SfPdfViewerThemeData(
|
||||
backgroundColor: AppTheme.primaryBackground,
|
||||
progressBarColor: AppTheme.accentColor,
|
||||
scrollStatusStyle: PdfScrollStatusStyle(
|
||||
backgroundColor: AppTheme.primaryBackground,
|
||||
),
|
||||
scrollHeadStyle: PdfScrollHeadStyle(
|
||||
backgroundColor: AppTheme.accentColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: SfPdfViewer.memory(
|
||||
Uint8List.fromList(_pdfBytes!),
|
||||
canShowScrollHead: false,
|
||||
canShowScrollStatus: false,
|
||||
enableDoubleTapZooming: true,
|
||||
enableTextSelection: false,
|
||||
),
|
||||
),
|
||||
);
|
||||
} else if (_error != null) {
|
||||
return Expanded(
|
||||
child: Center(
|
||||
child: Text(
|
||||
_error!,
|
||||
style: TextStyle(color: AppTheme.primaryText),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return const Expanded(
|
||||
child: Center(
|
||||
child: CircularProgressIndicator(
|
||||
valueColor: AlwaysStoppedAnimation<Color>(AppTheme.accentColor),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
} else if (_isVideoFile()) {
|
||||
if (kIsWeb && _videoViewType != null) {
|
||||
// Use HTML video element for web
|
||||
|
||||
Reference in New Issue
Block a user