solved some pr comments

This commit is contained in:
Lars Neuhaus 2024-04-06 13:34:52 +02:00
parent 277b3366f9
commit e901f139d6
2 changed files with 43 additions and 30 deletions

View File

@ -1,5 +1,4 @@
import 'dart:developer';
import 'dart:io';
import 'package:flutter/material.dart';
@ -92,8 +91,6 @@ class _FilesState extends State<Files> {
ListFilesCache(
path: widget.path.isEmpty ? '/' : widget.path.join('/'),
onUpdate: (ListFilesResponse d) {
log('_query');
if(!context.mounted) return; // prevent setState when widget is possibly already disposed
d.files.removeWhere((element) => element.name.isEmpty || element.name == widget.path.lastOrNull());
setState(() {
data = d;

View File

@ -6,6 +6,7 @@ import 'package:nextcloud/nextcloud.dart';
import 'package:uuid/uuid.dart';
import '../../../api/marianumcloud/webdav/webdavApi.dart';
import '../../../widget/confirmDialog.dart';
import '../../../widget/focusBehaviour.dart';
class FilesUploadDialog extends StatefulWidget {
@ -32,29 +33,34 @@ class UploadableFile {
class _FilesUploadDialogState extends State<FilesUploadDialog> {
final List<UploadableFile> _uploadableFiles = [];
late List<UploadableFile> _uploadableFiles;
bool _isUploading = false;
double _progressValue = 0.0;
double _overallProgressValue = 0.0;
String _infoText = '';
@override
void initState() {
super.initState();
_uploadableFiles.addAll(widget.filePaths.map((filePath) {
_uploadableFiles = widget.filePaths.map((filePath) {
String fileName = filePath.split(Platform.pathSeparator).last;
return UploadableFile(filePath, fileName);
}));
}).toList();
/*_uploadableFiles.addAll(widget.filePaths.map((filePath) {
String fileName = filePath.split(Platform.pathSeparator).last;
return UploadableFile(filePath, fileName);
}));*/
}
void showErrorMessage(int errorCode){
void showHttpErrorCode(int httpErrorCode){
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text('Ein Fehler ist aufgetreten'),
contentPadding: const EdgeInsets.all(10),
content: Text('Error code: $errorCode'),
content: Text('Error code: $httpErrorCode'),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
@ -66,31 +72,27 @@ class _FilesUploadDialogState extends State<FilesUploadDialog> {
);
}
void uploadSelectedFiles({bool override = false}) async {
void uploadFiles({bool override = false}) async {
setState(() {
_isUploading = true;
_infoText = 'Vorbereiten';
for (var file in _uploadableFiles) {
file.isConflicting = false;
}
});
for (var element in _uploadableFiles) {
setState(() {
element.isConflicting = false;
});
}
WebDavClient webdavClient = await WebdavApi.webdav;
if (!override) {
List<WebDavResponse> result = (await webdavClient.propfind(PathUri.parse(widget.remotePath))).responses;
List<UploadableFile> conflictingFiles = [];
for (var file in _uploadableFiles) {
List<UploadableFile> conflictingFiles = _uploadableFiles.where((file) {
String fileName = file.fileName;
if (result.any((element) => Uri.decodeComponent(element.href!).endsWith('/$fileName'))) {
// konflikt
conflictingFiles.add(file);
return true;
}
}
return false;
}).toList();
if(conflictingFiles.isNotEmpty) {
bool replaceFiles = await showDialog(
@ -120,9 +122,23 @@ class _FilesUploadDialogState extends State<FilesUploadDialog> {
),
TextButton(
onPressed: () {
Navigator.pop(context, true);
showDialog(
context: context,
builder: (context) {
return ConfirmDialog(
title: 'Bist du sicher?',
content: '',
onConfirm: () {
Navigator.pop(context, true);
},
confirmButton: 'Ja',
cancelButton: 'Nein',
);
}
);
},
child: const Text('Ersetzen', textAlign: TextAlign.center),
child: const Text('Überschreiben', textAlign: TextAlign.center),
),
],
);
@ -135,7 +151,7 @@ class _FilesUploadDialogState extends State<FilesUploadDialog> {
}
setState(() {
_isUploading = false;
_progressValue = 0.0;
_overallProgressValue = 0.0;
_infoText = '';
});
return;
@ -163,7 +179,7 @@ class _FilesUploadDialogState extends State<FilesUploadDialog> {
onProgress: (progress) {
setState(() {
file._uploadProgress = progress;
_progressValue = ((progress + _uploadableFiles.indexOf(file)) / _uploadableFiles.length).toDouble();
_overallProgressValue = ((progress + _uploadableFiles.indexOf(file)) / _uploadableFiles.length).toDouble();
});
},
);
@ -172,11 +188,11 @@ class _FilesUploadDialogState extends State<FilesUploadDialog> {
// error code
setState(() {
_isUploading = false;
_progressValue = 0.0;
_overallProgressValue = 0.0;
_infoText = '';
});
Navigator.of(context).pop();
showErrorMessage(uploadTask.statusCode);
showHttpErrorCode(uploadTask.statusCode);
} else {
uploadetFilePaths.add(fullRemotePath);
}
@ -184,7 +200,7 @@ class _FilesUploadDialogState extends State<FilesUploadDialog> {
setState(() {
_isUploading = false;
_progressValue = 0.0;
_overallProgressValue = 0.0;
_infoText = '';
});
Navigator.of(context).pop();
@ -296,13 +312,13 @@ class _FilesUploadDialogState extends State<FilesUploadDialog> {
Visibility(
visible: _isUploading,
replacement: TextButton(
onPressed: () => uploadSelectedFiles(override: widget.uniqueNames),
onPressed: () => uploadFiles(override: widget.uniqueNames),
child: const Text('Hochladen'),
),
child: Stack(
alignment: Alignment.center,
children: [
CircularProgressIndicator(value: _progressValue),
CircularProgressIndicator(value: _overallProgressValue),
Center(child: Text(_infoText)),
],
),