Refactor ShareFileDialog to improve UI layout, error handling, and share link management

This commit is contained in:
Leon Bösche
2026-01-24 21:53:13 +01:00
parent b703a209d0
commit d8133347f0

View File

@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../services/api_client.dart';
import '../theme/app_theme.dart';
import '../theme/modern_glass_button.dart';
import '../injection.dart';
class ShareFileDialog extends StatefulWidget {
@@ -24,7 +25,6 @@ class _ShareFileDialogState extends State<ShareFileDialog> {
bool _isLoading = true;
String? _shareUrl;
String? _error;
late final TextEditingController _urlController = TextEditingController();
@override
void initState() {
@@ -32,12 +32,6 @@ class _ShareFileDialogState extends State<ShareFileDialog> {
_loadShareLink();
}
@override
void dispose() {
_urlController.dispose();
super.dispose();
}
Future<void> _loadShareLink() async {
setState(() {
_isLoading = true;
@@ -53,7 +47,6 @@ class _ShareFileDialogState extends State<ShareFileDialog> {
if (response['exists'] == true) {
setState(() {
_shareUrl = response['url'];
_urlController.text = _shareUrl!;
_isLoading = false;
});
} else {
@@ -81,7 +74,6 @@ class _ShareFileDialogState extends State<ShareFileDialog> {
setState(() {
_shareUrl = response['url'];
_urlController.text = _shareUrl!;
_isLoading = false;
});
} catch (e) {
@@ -106,7 +98,6 @@ class _ShareFileDialogState extends State<ShareFileDialog> {
setState(() {
_shareUrl = null;
_urlController.clear();
_isLoading = false;
});
} catch (e) {
@@ -129,15 +120,17 @@ class _ShareFileDialogState extends State<ShareFileDialog> {
@override
Widget build(BuildContext context) {
return Dialog(
backgroundColor: Colors.transparent,
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 500),
backgroundColor: AppTheme.primaryBackground,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
child: Container(
decoration: AppTheme.glassDecoration,
width: 500,
constraints: const BoxConstraints(maxHeight: 400),
padding: const EdgeInsets.all(24),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Header
Row(
children: [
Text(
'Share "${widget.fileName}"',
@@ -147,6 +140,15 @@ class _ShareFileDialogState extends State<ShareFileDialog> {
fontWeight: FontWeight.bold,
),
),
const Spacer(),
IconButton(
onPressed: () => Navigator.of(context).pop(),
icon: Icon(Icons.close, color: AppTheme.secondaryText),
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
),
],
),
const SizedBox(height: 16),
if (_isLoading)
const Center(
@@ -157,7 +159,23 @@ class _ShareFileDialogState extends State<ShareFileDialog> {
),
)
else if (_error != null)
Text(_error!, style: TextStyle(color: Colors.red[400]))
Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
_error!,
style: TextStyle(color: AppTheme.errorColor),
textAlign: TextAlign.center,
),
const SizedBox(height: 16),
ModernGlassButton(
onPressed: _loadShareLink,
child: const Text('Retry'),
),
],
),
)
else
Column(
crossAxisAlignment: CrossAxisAlignment.start,
@@ -167,28 +185,32 @@ class _ShareFileDialogState extends State<ShareFileDialog> {
style: TextStyle(color: AppTheme.secondaryText),
),
const SizedBox(height: 16),
TextField(
controller: _urlController,
readOnly: true,
Row(
children: [
Expanded(
child: Text(
_shareUrl!,
maxLines: 2,
decoration: InputDecoration(
labelText: 'Share link',
border: const OutlineInputBorder(),
suffixIcon: IconButton(
icon: const Icon(Icons.copy),
overflow: TextOverflow.ellipsis,
style: TextStyle(color: AppTheme.primaryText),
),
),
const SizedBox(width: 16),
ModernGlassButton(
onPressed: _copyToClipboard,
child: const Icon(Icons.content_copy),
),
),
],
),
const SizedBox(height: 16),
Row(
children: [
TextButton(
ModernGlassButton(
onPressed: _revokeShareLink,
style: TextButton.styleFrom(
foregroundColor: Colors.red[400],
child: Text(
'Revoke Link',
style: TextStyle(color: AppTheme.errorColor),
),
child: const Text('Revoke Link'),
),
const Spacer(),
TextButton(
@@ -202,7 +224,6 @@ class _ShareFileDialogState extends State<ShareFileDialog> {
],
),
),
),
);
}
}