dart format
This commit is contained in:
@@ -15,7 +15,13 @@ class FilesUploadDialog extends StatefulWidget {
|
||||
final void Function(List<String> uploadedFilePaths) onUploadFinished;
|
||||
final bool uniqueNames;
|
||||
|
||||
const FilesUploadDialog({super.key, required this.filePaths, required this.remotePath, required this.onUploadFinished, this.uniqueNames = false});
|
||||
const FilesUploadDialog({
|
||||
super.key,
|
||||
required this.filePaths,
|
||||
required this.remotePath,
|
||||
required this.onUploadFinished,
|
||||
this.uniqueNames = false,
|
||||
});
|
||||
|
||||
@override
|
||||
State<FilesUploadDialog> createState() => _FilesUploadDialogState();
|
||||
@@ -31,7 +37,6 @@ class UploadableFile {
|
||||
UploadableFile(this.filePath, this.fileName);
|
||||
}
|
||||
|
||||
|
||||
class _FilesUploadDialogState extends State<FilesUploadDialog> {
|
||||
late List<UploadableFile> _uploadableFiles;
|
||||
bool _isUploading = false;
|
||||
@@ -63,7 +68,12 @@ class _FilesUploadDialogState extends State<FilesUploadDialog> {
|
||||
_overallProgressValue = 0.0;
|
||||
_infoText = '';
|
||||
});
|
||||
InfoDialog.show(context, message, title: 'Upload fehlgeschlagen', copyable: true);
|
||||
InfoDialog.show(
|
||||
context,
|
||||
message,
|
||||
title: 'Upload fehlgeschlagen',
|
||||
copyable: true,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> uploadFiles({bool override = false}) async {
|
||||
@@ -80,7 +90,9 @@ class _FilesUploadDialogState extends State<FilesUploadDialog> {
|
||||
if (!override) {
|
||||
List<dynamic> result;
|
||||
try {
|
||||
result = (await webdavClient.propfind(PathUri.parse(widget.remotePath))).responses;
|
||||
result = (await webdavClient.propfind(
|
||||
PathUri.parse(widget.remotePath),
|
||||
)).responses;
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
_showUploadError('Verbindung fehlgeschlagen: $e');
|
||||
@@ -88,7 +100,11 @@ class _FilesUploadDialogState extends State<FilesUploadDialog> {
|
||||
}
|
||||
final conflictingFiles = _uploadableFiles.where((file) {
|
||||
final fileName = file.fileName;
|
||||
return result.any((element) => Uri.decodeComponent((element as WebDavResponse).href!).endsWith('/$fileName'));
|
||||
return result.any(
|
||||
(element) => Uri.decodeComponent(
|
||||
(element as WebDavResponse).href!,
|
||||
).endsWith('/$fileName'),
|
||||
);
|
||||
}).toList();
|
||||
|
||||
if (conflictingFiles.isNotEmpty) {
|
||||
@@ -97,46 +113,46 @@ class _FilesUploadDialogState extends State<FilesUploadDialog> {
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => AlertDialog(
|
||||
contentPadding: const EdgeInsets.all(10),
|
||||
title: const Text('Konflikt', textAlign: TextAlign.center),
|
||||
content: conflictingFiles.length == 1 ?
|
||||
Text(
|
||||
'Eine Datei mit dem Namen "${conflictingFiles.map((e) => e.fileName).first}" existiert bereits.',
|
||||
textAlign: TextAlign.left,
|
||||
) :
|
||||
SingleChildScrollView(
|
||||
child: Text(
|
||||
'${conflictingFiles.length} Dateien mit folgenden Namen existieren bereits: \n${conflictingFiles.map((e) => '\n - ${e.fileName}').join('')}',
|
||||
textAlign: TextAlign.left,
|
||||
),
|
||||
contentPadding: const EdgeInsets.all(10),
|
||||
title: const Text('Konflikt', textAlign: TextAlign.center),
|
||||
content: conflictingFiles.length == 1
|
||||
? Text(
|
||||
'Eine Datei mit dem Namen "${conflictingFiles.map((e) => e.fileName).first}" existiert bereits.',
|
||||
textAlign: TextAlign.left,
|
||||
)
|
||||
: SingleChildScrollView(
|
||||
child: Text(
|
||||
'${conflictingFiles.length} Dateien mit folgenden Namen existieren bereits: \n${conflictingFiles.map((e) => '\n - ${e.fileName}').join('')}',
|
||||
textAlign: TextAlign.left,
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context, false);
|
||||
},
|
||||
child: const Text('Bearbeiten', textAlign: TextAlign.center),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context, false);
|
||||
},
|
||||
child: const Text('Bearbeiten', textAlign: TextAlign.center),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => ConfirmDialog(
|
||||
title: 'Bestätigen?',
|
||||
content: 'Bist du sicher, dass du ${conflictingFiles.length} Dateien überschreiben möchtest?',
|
||||
onConfirm: () {
|
||||
Navigator.pop(context, true);
|
||||
},
|
||||
confirmButton: 'Ja',
|
||||
cancelButton: 'Nein',
|
||||
),
|
||||
);
|
||||
|
||||
},
|
||||
child: const Text('Überschreiben', textAlign: TextAlign.center),
|
||||
),
|
||||
],
|
||||
)
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => ConfirmDialog(
|
||||
title: 'Bestätigen?',
|
||||
content:
|
||||
'Bist du sicher, dass du ${conflictingFiles.length} Dateien überschreiben möchtest?',
|
||||
onConfirm: () {
|
||||
Navigator.pop(context, true);
|
||||
},
|
||||
confirmButton: 'Ja',
|
||||
cancelButton: 'Nein',
|
||||
),
|
||||
);
|
||||
},
|
||||
child: const Text('Überschreiben', textAlign: TextAlign.center),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
if (replaceFiles != true) {
|
||||
@@ -160,13 +176,15 @@ class _FilesUploadDialogState extends State<FilesUploadDialog> {
|
||||
|
||||
if (widget.uniqueNames) {
|
||||
final unique = DateTime.now().microsecondsSinceEpoch.toRadixString(36);
|
||||
fileName = '${fileName.split('.').first}-$unique.${fileName.split('.').last}';
|
||||
fileName =
|
||||
'${fileName.split('.').first}-$unique.${fileName.split('.').last}';
|
||||
}
|
||||
|
||||
var fullRemotePath = '${widget.remotePath}/$fileName';
|
||||
|
||||
setState(() {
|
||||
_infoText = '${_uploadableFiles.indexOf(file) + 1}/${_uploadableFiles.length}';
|
||||
_infoText =
|
||||
'${_uploadableFiles.indexOf(file) + 1}/${_uploadableFiles.length}';
|
||||
});
|
||||
|
||||
final HttpClientResponse uploadTask;
|
||||
@@ -178,7 +196,10 @@ class _FilesUploadDialogState extends State<FilesUploadDialog> {
|
||||
onProgress: (progress) {
|
||||
setState(() {
|
||||
file._uploadProgress = progress;
|
||||
_overallProgressValue = ((progress + _uploadableFiles.indexOf(file)) / _uploadableFiles.length).toDouble();
|
||||
_overallProgressValue =
|
||||
((progress + _uploadableFiles.indexOf(file)) /
|
||||
_uploadableFiles.length)
|
||||
.toDouble();
|
||||
});
|
||||
},
|
||||
);
|
||||
@@ -188,7 +209,7 @@ class _FilesUploadDialogState extends State<FilesUploadDialog> {
|
||||
return;
|
||||
}
|
||||
|
||||
if(uploadTask.statusCode < 200 || uploadTask.statusCode > 299) {
|
||||
if (uploadTask.statusCode < 200 || uploadTask.statusCode > 299) {
|
||||
setState(() {
|
||||
_isUploading = false;
|
||||
_overallProgressValue = 0.0;
|
||||
@@ -214,119 +235,133 @@ class _FilesUploadDialogState extends State<FilesUploadDialog> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Dateien hochladen'),
|
||||
automaticallyImplyLeading: false,
|
||||
),
|
||||
body: LoaderOverlay(
|
||||
overlayWholeScreen: true,
|
||||
child: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: _uploadableFiles.length,
|
||||
itemBuilder: (context, index) {
|
||||
final currentFile = _uploadableFiles[index];
|
||||
currentFile.fileNameController.text = currentFile.fileName;
|
||||
return ListTile(
|
||||
title: TextField(
|
||||
readOnly: _isUploading,
|
||||
controller: currentFile.fileNameController,
|
||||
decoration: InputDecoration(
|
||||
border: const UnderlineInputBorder(),
|
||||
label: Text('Datei ${index+1}'),
|
||||
errorText: currentFile.isConflicting ? 'existiert bereits' : null,
|
||||
errorStyle: TextStyle(color: Theme.of(context).colorScheme.error),
|
||||
appBar: AppBar(
|
||||
title: const Text('Dateien hochladen'),
|
||||
automaticallyImplyLeading: false,
|
||||
),
|
||||
body: LoaderOverlay(
|
||||
overlayWholeScreen: true,
|
||||
child: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: _uploadableFiles.length,
|
||||
itemBuilder: (context, index) {
|
||||
final currentFile = _uploadableFiles[index];
|
||||
currentFile.fileNameController.text = currentFile.fileName;
|
||||
return ListTile(
|
||||
title: TextField(
|
||||
readOnly: _isUploading,
|
||||
controller: currentFile.fileNameController,
|
||||
decoration: InputDecoration(
|
||||
border: const UnderlineInputBorder(),
|
||||
label: Text('Datei ${index + 1}'),
|
||||
errorText: currentFile.isConflicting
|
||||
? 'existiert bereits'
|
||||
: null,
|
||||
errorStyle: TextStyle(
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
onChanged: (input) {
|
||||
currentFile.fileName = input;
|
||||
},
|
||||
onTapOutside: (PointerDownEvent event) {
|
||||
FocusBehaviour.textFieldTapOutside(context);
|
||||
if(currentFile.isConflicting){
|
||||
setState(() {
|
||||
currentFile.isConflicting = false;
|
||||
});
|
||||
}
|
||||
},
|
||||
onEditingComplete: () {
|
||||
if(currentFile.isConflicting){
|
||||
setState(() {
|
||||
currentFile.isConflicting = false;
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
subtitle: _isUploading && (currentFile._uploadProgress ?? 0) < 1 ? LinearProgressIndicator(
|
||||
value: currentFile._uploadProgress,
|
||||
borderRadius: const BorderRadius.all(Radius.circular(2)),
|
||||
) : null,
|
||||
trailing: Container(
|
||||
width: 24,
|
||||
height: 24,
|
||||
onChanged: (input) {
|
||||
currentFile.fileName = input;
|
||||
},
|
||||
onTapOutside: (PointerDownEvent event) {
|
||||
FocusBehaviour.textFieldTapOutside(context);
|
||||
if (currentFile.isConflicting) {
|
||||
setState(() {
|
||||
currentFile.isConflicting = false;
|
||||
});
|
||||
}
|
||||
},
|
||||
onEditingComplete: () {
|
||||
if (currentFile.isConflicting) {
|
||||
setState(() {
|
||||
currentFile.isConflicting = false;
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
subtitle:
|
||||
_isUploading && (currentFile._uploadProgress ?? 0) < 1
|
||||
? LinearProgressIndicator(
|
||||
value: currentFile._uploadProgress,
|
||||
borderRadius: const BorderRadius.all(
|
||||
Radius.circular(2),
|
||||
),
|
||||
)
|
||||
: null,
|
||||
trailing: Container(
|
||||
width: 24,
|
||||
height: 24,
|
||||
padding: EdgeInsets.zero,
|
||||
child: IconButton(
|
||||
tooltip: 'Datei entfernen',
|
||||
padding: EdgeInsets.zero,
|
||||
child: IconButton(
|
||||
tooltip: 'Datei entfernen',
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: () {
|
||||
if(!_isUploading) {
|
||||
if(_uploadableFiles.length-1 <= 0) Navigator.of(context).pop();
|
||||
setState(() {
|
||||
_uploadableFiles.removeAt(index);
|
||||
});
|
||||
onPressed: () {
|
||||
if (!_isUploading) {
|
||||
if (_uploadableFiles.length - 1 <= 0) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
},
|
||||
icon: const Icon(Icons.delete_outlined),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 15, right: 15, bottom: 15, top: 5),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
Visibility(
|
||||
visible: !_isUploading,
|
||||
child: TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('Abbrechen'),
|
||||
setState(() {
|
||||
_uploadableFiles.removeAt(index);
|
||||
});
|
||||
}
|
||||
},
|
||||
icon: const Icon(Icons.delete_outlined),
|
||||
),
|
||||
),
|
||||
const Expanded(child: SizedBox.shrink()),
|
||||
Visibility(
|
||||
visible: _isUploading,
|
||||
replacement: TextButton(
|
||||
onPressed: () => uploadFiles(override: widget.uniqueNames),
|
||||
child: const Text('Hochladen'),
|
||||
),
|
||||
child: Visibility(
|
||||
visible: _infoText.length < 5,
|
||||
replacement: Row(
|
||||
children: [
|
||||
Text(_infoText),
|
||||
const SizedBox(width: 15),
|
||||
CircularProgressIndicator(value: _overallProgressValue),
|
||||
],
|
||||
),
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
CircularProgressIndicator(value: _overallProgressValue),
|
||||
Center(child: Text(_infoText)),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 15,
|
||||
right: 15,
|
||||
bottom: 15,
|
||||
top: 5,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
Visibility(
|
||||
visible: !_isUploading,
|
||||
child: TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('Abbrechen'),
|
||||
),
|
||||
),
|
||||
const Expanded(child: SizedBox.shrink()),
|
||||
Visibility(
|
||||
visible: _isUploading,
|
||||
replacement: TextButton(
|
||||
onPressed: () => uploadFiles(override: widget.uniqueNames),
|
||||
child: const Text('Hochladen'),
|
||||
),
|
||||
child: Visibility(
|
||||
visible: _infoText.length < 5,
|
||||
replacement: Row(
|
||||
children: [
|
||||
Text(_infoText),
|
||||
const SizedBox(width: 15),
|
||||
CircularProgressIndicator(value: _overallProgressValue),
|
||||
],
|
||||
),
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
CircularProgressIndicator(value: _overallProgressValue),
|
||||
Center(child: Text(_infoText)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user