Reorder PublicFileViewer header: download button left, close button right, add 4px top padding

This commit is contained in:
Leon Bösche
2026-01-25 00:57:55 +01:00
parent c29bd89a0a
commit 8fd0ded519
2 changed files with 147 additions and 28 deletions

View File

@@ -59,15 +59,22 @@ class _PublicFileViewerState extends State<PublicFileViewer> {
}
Future<void> _initializeVideoPlayer() async {
if (_fileData?['downloadUrl'] != null) {
_videoController = VideoPlayerController.networkUrl(
Uri.parse(_fileData!['downloadUrl']),
);
final url = _fileData?['viewUrl'] ?? _fileData?['downloadUrl'];
if (url != null) {
_videoController = VideoPlayerController.networkUrl(Uri.parse(url));
await _videoController!.initialize();
setState(() {});
}
}
String? _getViewUrl() {
return _fileData?['viewUrl'] ?? _fileData?['downloadUrl'];
}
String? _getDownloadUrl() {
return _fileData?['downloadUrl'];
}
bool _isVideoFile() {
final mimeType = _fileData?['capabilities']?['mimeType'] ?? '';
return mimeType.toString().startsWith('video/');
@@ -93,20 +100,24 @@ class _PublicFileViewerState extends State<PublicFileViewer> {
}
void _downloadFile() {
if (_fileData != null && _fileData!['downloadUrl'] != null) {
final downloadUrl = _getDownloadUrl();
if (downloadUrl != null) {
// Trigger download directly in browser
final anchor = web.HTMLAnchorElement()
..href = _fileData!['downloadUrl']
..href = downloadUrl
..download = _fileData!['fileName'] ?? 'download';
anchor.click();
}
}
Widget _buildFilePreview() {
final viewUrl = _getViewUrl();
if (viewUrl == null) return const SizedBox();
if (_isPdfFile()) {
return Expanded(
child: SfPdfViewer.network(
_fileData!['downloadUrl'],
viewUrl,
canShowScrollHead: false,
canShowScrollStatus: false,
enableDoubleTapZooming: true,
@@ -123,7 +134,7 @@ class _PublicFileViewerState extends State<PublicFileViewer> {
} else if (_isAudioFile()) {
return AudioPlayerBar(
fileName: _fileData!['fileName'] ?? 'Audio',
fileUrl: _fileData!['downloadUrl'],
fileUrl: viewUrl,
);
} else if (_isDocumentFile()) {
return Expanded(
@@ -195,30 +206,31 @@ class _PublicFileViewerState extends State<PublicFileViewer> {
appBar: AppBar(
backgroundColor: AppTheme.primaryBackground,
elevation: 0,
leading: IconButton(
icon: const Icon(Icons.close, color: AppTheme.primaryText),
onPressed: () => context.go('/'),
),
leading: _fileData != null
? Padding(
padding: const EdgeInsets.only(left: 16, top: 4),
child: ModernGlassButton(
onPressed: _downloadFile,
child: const Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.download, size: 18),
SizedBox(width: 8),
Text('Download'),
],
),
),
)
: null,
title: Text(
_fileData?['fileName'] ?? 'Shared File',
style: TextStyle(color: AppTheme.primaryText),
),
actions: [
if (_fileData != null)
Padding(
padding: const EdgeInsets.only(right: 8),
child: ModernGlassButton(
onPressed: _downloadFile,
child: const Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.download, size: 18),
SizedBox(width: 8),
Text('Download'),
],
),
),
),
IconButton(
icon: const Icon(Icons.close, color: AppTheme.primaryText),
onPressed: () => context.go('/'),
),
],
),
body: _isLoading