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), onPressed: () => _downloadFile(file),
), ),
IconButton( IconButton(
icon: const Icon(Icons.share, color: AppTheme.secondaryText), icon: const Icon(
Icons.share_outlined,
color: AppTheme.secondaryText,
),
splashColor: Colors.transparent, splashColor: Colors.transparent,
highlightColor: Colors.transparent, highlightColor: Colors.transparent,
onPressed: () => _shareFile(file), onPressed: () => _shareFile(file),

View File

@@ -82,6 +82,11 @@ class _PublicFileViewerState extends State<PublicFileViewer> {
) )
: _error != null : _error != null
? Padding( ? Padding(
padding: const EdgeInsets.all(24),
child: Card(
color: AppTheme.primaryBackground,
elevation: 4,
child: Padding(
padding: const EdgeInsets.all(24), padding: const EdgeInsets.all(24),
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
@@ -98,9 +103,16 @@ class _PublicFileViewerState extends State<PublicFileViewer> {
), ),
], ],
), ),
),
),
) )
: _fileData != null : _fileData != null
? Padding( ? Padding(
padding: const EdgeInsets.all(24),
child: Card(
color: AppTheme.primaryBackground,
elevation: 4,
child: Padding(
padding: const EdgeInsets.all(24), padding: const EdgeInsets.all(24),
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
@@ -141,6 +153,8 @@ class _PublicFileViewerState extends State<PublicFileViewer> {
), ),
], ],
), ),
),
),
) )
: const SizedBox(), : const SizedBox(),
), ),

View File

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