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

@@ -82,6 +82,11 @@ class _PublicFileViewerState extends State<PublicFileViewer> {
)
: _error != null
? Padding(
padding: const EdgeInsets.all(24),
child: Card(
color: AppTheme.primaryBackground,
elevation: 4,
child: Padding(
padding: const EdgeInsets.all(24),
child: Column(
mainAxisSize: MainAxisSize.min,
@@ -98,9 +103,16 @@ class _PublicFileViewerState extends State<PublicFileViewer> {
),
],
),
),
),
)
: _fileData != null
? Padding(
padding: const EdgeInsets.all(24),
child: Card(
color: AppTheme.primaryBackground,
elevation: 4,
child: Padding(
padding: const EdgeInsets.all(24),
child: Column(
mainAxisSize: MainAxisSize.min,
@@ -141,6 +153,8 @@ class _PublicFileViewerState extends State<PublicFileViewer> {
),
],
),
),
),
)
: 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,
),
TextField(
controller: _urlController,
readOnly: true,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
),
IconButton(
icon: const Icon(
Icons.copy,
color: AppTheme.accentColor,
),
decoration: InputDecoration(
labelText: 'Share link',
border: const OutlineInputBorder(),
suffixIcon: IconButton(
icon: const Icon(Icons.copy),
onPressed: _copyToClipboard,
tooltip: 'Copy link',
),
],
),
),
const SizedBox(height: 16),