Refactor file sharing UI to use TextField for share link display and improve error handling

This commit is contained in:
Leon Bösche
2026-01-24 21:38:29 +01:00
parent 49c578cef2
commit 896f475b03
3 changed files with 91 additions and 80 deletions

View File

@@ -1310,7 +1310,10 @@ class _FileExplorerState extends State<FileExplorer>
onPressed: () => _downloadFile(file),
),
IconButton(
icon: const Icon(Icons.share, color: AppTheme.secondaryText),
icon: const Icon(
Icons.share_outlined,
color: AppTheme.secondaryText,
),
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
onPressed: () => _shareFile(file),

View File

@@ -83,63 +83,77 @@ class _PublicFileViewerState extends State<PublicFileViewer> {
: _error != null
? Padding(
padding: const EdgeInsets.all(24),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.link_off, size: 64, color: Colors.red[400]),
const SizedBox(height: 16),
Text(
_error!,
style: TextStyle(
color: AppTheme.primaryText,
fontSize: 18,
),
textAlign: TextAlign.center,
child: Card(
color: AppTheme.primaryBackground,
elevation: 4,
child: Padding(
padding: const EdgeInsets.all(24),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.link_off, size: 64, color: Colors.red[400]),
const SizedBox(height: 16),
Text(
_error!,
style: TextStyle(
color: AppTheme.primaryText,
fontSize: 18,
),
textAlign: TextAlign.center,
),
],
),
],
),
),
)
: _fileData != null
? Padding(
padding: const EdgeInsets.all(24),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
Icons.insert_drive_file,
size: 64,
color: AppTheme.primaryText,
),
const SizedBox(height: 16),
Text(
_fileData!['fileName'] ?? 'Unknown file',
style: TextStyle(
color: AppTheme.primaryText,
fontSize: 24,
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 8),
Text(
'Size: ${(_fileData!['fileSize'] ?? 0) ~/ 1024} KB',
style: TextStyle(color: AppTheme.secondaryText),
),
const SizedBox(height: 24),
ElevatedButton.icon(
onPressed: _downloadFile,
icon: const Icon(Icons.download),
label: const Text('Download File'),
style: ElevatedButton.styleFrom(
backgroundColor: AppTheme.accentColor,
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(
horizontal: 24,
vertical: 12,
child: Card(
color: AppTheme.primaryBackground,
elevation: 4,
child: Padding(
padding: const EdgeInsets.all(24),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
Icons.insert_drive_file,
size: 64,
color: AppTheme.primaryText,
),
),
const SizedBox(height: 16),
Text(
_fileData!['fileName'] ?? 'Unknown file',
style: TextStyle(
color: AppTheme.primaryText,
fontSize: 24,
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 8),
Text(
'Size: ${(_fileData!['fileSize'] ?? 0) ~/ 1024} KB',
style: TextStyle(color: AppTheme.secondaryText),
),
const SizedBox(height: 24),
ElevatedButton.icon(
onPressed: _downloadFile,
icon: const Icon(Icons.download),
label: const Text('Download File'),
style: ElevatedButton.styleFrom(
backgroundColor: AppTheme.accentColor,
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(
horizontal: 24,
vertical: 12,
),
),
),
],
),
],
),
),
)
: const SizedBox(),

View File

@@ -24,6 +24,7 @@ class _ShareFileDialogState extends State<ShareFileDialog> {
bool _isLoading = true;
String? _shareUrl;
String? _error;
late final TextEditingController _urlController = TextEditingController();
@override
void initState() {
@@ -31,6 +32,12 @@ class _ShareFileDialogState extends State<ShareFileDialog> {
_loadShareLink();
}
@override
void dispose() {
_urlController.dispose();
super.dispose();
}
Future<void> _loadShareLink() async {
setState(() {
_isLoading = true;
@@ -46,17 +53,20 @@ class _ShareFileDialogState extends State<ShareFileDialog> {
if (response['exists'] == true) {
setState(() {
_shareUrl = response['url'];
_urlController.text = _shareUrl!;
_isLoading = false;
});
} else {
setState(() {
_shareUrl = null;
_urlController.clear();
_isLoading = false;
});
}
} catch (e) {
setState(() {
_error = 'Failed to load share link';
_shareUrl = null;
_urlController.clear();
_isLoading = false;
});
}
@@ -77,6 +87,7 @@ class _ShareFileDialogState extends State<ShareFileDialog> {
setState(() {
_shareUrl = response['url'];
_urlController.text = _shareUrl!;
_isLoading = false;
});
} catch (e) {
@@ -101,6 +112,7 @@ class _ShareFileDialogState extends State<ShareFileDialog> {
setState(() {
_shareUrl = null;
_urlController.clear();
_isLoading = false;
});
} catch (e) {
@@ -180,35 +192,17 @@ class _ShareFileDialogState extends State<ShareFileDialog> {
style: TextStyle(color: AppTheme.secondaryText),
),
const SizedBox(height: 16),
Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.white.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(8),
),
child: Row(
children: [
Expanded(
child: Text(
_shareUrl!,
style: TextStyle(
color: AppTheme.primaryText,
fontFamily: 'monospace',
fontSize: 14,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
),
IconButton(
icon: const Icon(
Icons.copy,
color: AppTheme.accentColor,
),
onPressed: _copyToClipboard,
tooltip: 'Copy link',
),
],
TextField(
controller: _urlController,
readOnly: true,
maxLines: 2,
decoration: InputDecoration(
labelText: 'Share link',
border: const OutlineInputBorder(),
suffixIcon: IconButton(
icon: const Icon(Icons.copy),
onPressed: _copyToClipboard,
),
),
),
const SizedBox(height: 16),