Refactor file sharing UI to use TextField for share link display and improve error handling
This commit is contained in:
@@ -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),
|
||||||
|
|||||||
@@ -83,63 +83,77 @@ class _PublicFileViewerState extends State<PublicFileViewer> {
|
|||||||
: _error != null
|
: _error != null
|
||||||
? Padding(
|
? Padding(
|
||||||
padding: const EdgeInsets.all(24),
|
padding: const EdgeInsets.all(24),
|
||||||
child: Column(
|
child: Card(
|
||||||
mainAxisSize: MainAxisSize.min,
|
color: AppTheme.primaryBackground,
|
||||||
children: [
|
elevation: 4,
|
||||||
Icon(Icons.link_off, size: 64, color: Colors.red[400]),
|
child: Padding(
|
||||||
const SizedBox(height: 16),
|
padding: const EdgeInsets.all(24),
|
||||||
Text(
|
child: Column(
|
||||||
_error!,
|
mainAxisSize: MainAxisSize.min,
|
||||||
style: TextStyle(
|
children: [
|
||||||
color: AppTheme.primaryText,
|
Icon(Icons.link_off, size: 64, color: Colors.red[400]),
|
||||||
fontSize: 18,
|
const SizedBox(height: 16),
|
||||||
),
|
Text(
|
||||||
textAlign: TextAlign.center,
|
_error!,
|
||||||
|
style: TextStyle(
|
||||||
|
color: AppTheme.primaryText,
|
||||||
|
fontSize: 18,
|
||||||
|
),
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
: _fileData != null
|
: _fileData != null
|
||||||
? Padding(
|
? Padding(
|
||||||
padding: const EdgeInsets.all(24),
|
padding: const EdgeInsets.all(24),
|
||||||
child: Column(
|
child: Card(
|
||||||
mainAxisSize: MainAxisSize.min,
|
color: AppTheme.primaryBackground,
|
||||||
children: [
|
elevation: 4,
|
||||||
Icon(
|
child: Padding(
|
||||||
Icons.insert_drive_file,
|
padding: const EdgeInsets.all(24),
|
||||||
size: 64,
|
child: Column(
|
||||||
color: AppTheme.primaryText,
|
mainAxisSize: MainAxisSize.min,
|
||||||
),
|
children: [
|
||||||
const SizedBox(height: 16),
|
Icon(
|
||||||
Text(
|
Icons.insert_drive_file,
|
||||||
_fileData!['fileName'] ?? 'Unknown file',
|
size: 64,
|
||||||
style: TextStyle(
|
color: AppTheme.primaryText,
|
||||||
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(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(),
|
: const SizedBox(),
|
||||||
|
|||||||
@@ -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),
|
maxLines: 2,
|
||||||
borderRadius: BorderRadius.circular(8),
|
decoration: InputDecoration(
|
||||||
),
|
labelText: 'Share link',
|
||||||
child: Row(
|
border: const OutlineInputBorder(),
|
||||||
children: [
|
suffixIcon: IconButton(
|
||||||
Expanded(
|
icon: const Icon(Icons.copy),
|
||||||
child: Text(
|
onPressed: _copyToClipboard,
|
||||||
_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',
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
|
|||||||
Reference in New Issue
Block a user