Frontend: unify PDF viewer to use network URL like internal viewer, remove bytes loading hack
This commit is contained in:
@@ -26,7 +26,6 @@ class _PublicFileViewerState extends State<PublicFileViewer> {
|
|||||||
String? _error;
|
String? _error;
|
||||||
Map<String, dynamic>? _fileData;
|
Map<String, dynamic>? _fileData;
|
||||||
VideoPlayerController? _videoController;
|
VideoPlayerController? _videoController;
|
||||||
List<int>? _pdfBytes;
|
|
||||||
String? _videoViewType;
|
String? _videoViewType;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -51,11 +50,6 @@ class _PublicFileViewerState extends State<PublicFileViewer> {
|
|||||||
_isLoading = false;
|
_isLoading = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Load PDF bytes if it's a PDF file
|
|
||||||
if (_isPdfFile()) {
|
|
||||||
await _loadPdfBytes();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize video player if it's a video file
|
// Initialize video player if it's a video file
|
||||||
if (_isVideoFile()) {
|
if (_isVideoFile()) {
|
||||||
await _initializeVideoPlayer();
|
await _initializeVideoPlayer();
|
||||||
@@ -68,28 +62,6 @@ class _PublicFileViewerState extends State<PublicFileViewer> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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.';
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _initializeVideoPlayer() async {
|
Future<void> _initializeVideoPlayer() async {
|
||||||
if (!kIsWeb) {
|
if (!kIsWeb) {
|
||||||
// For mobile, use VideoPlayerController
|
// For mobile, use VideoPlayerController
|
||||||
@@ -184,35 +156,20 @@ class _PublicFileViewerState extends State<PublicFileViewer> {
|
|||||||
if (viewUrl == null) return const SizedBox();
|
if (viewUrl == null) return const SizedBox();
|
||||||
|
|
||||||
if (_isPdfFile()) {
|
if (_isPdfFile()) {
|
||||||
if (_pdfBytes != null) {
|
|
||||||
return Expanded(
|
return Expanded(
|
||||||
child: SfPdfViewer.memory(
|
child: SfPdfViewer.network(
|
||||||
Uint8List.fromList(_pdfBytes!),
|
viewUrl,
|
||||||
|
onDocumentLoadFailed: (details) {
|
||||||
|
setState(() {
|
||||||
|
_error = 'Failed to load PDF: ${details.description}';
|
||||||
|
});
|
||||||
|
},
|
||||||
canShowScrollHead: false,
|
canShowScrollHead: false,
|
||||||
canShowScrollStatus: false,
|
canShowScrollStatus: false,
|
||||||
enableDoubleTapZooming: true,
|
enableDoubleTapZooming: true,
|
||||||
enableTextSelection: false,
|
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()) {
|
} else if (_isVideoFile()) {
|
||||||
if (kIsWeb && _videoViewType != null) {
|
if (kIsWeb && _videoViewType != null) {
|
||||||
// Use HTML video element for web
|
// Use HTML video element for web
|
||||||
|
|||||||
Reference in New Issue
Block a user