updated project style guidelines
This commit is contained in:
@ -26,14 +26,14 @@ class FileElement extends StatefulWidget {
|
||||
const FileElement(this.file, this.path, this.refetch, {super.key});
|
||||
|
||||
static Future<DownloaderCore> download(BuildContext context, String remotePath, String name, Function(double) onProgress, Function(OpenResult) onDone) async {
|
||||
Directory paths = await getTemporaryDirectory();
|
||||
var paths = await getTemporaryDirectory();
|
||||
|
||||
var encodedPath = Uri.encodeComponent(remotePath);
|
||||
encodedPath = encodedPath.replaceAll('%2F', '/');
|
||||
|
||||
String local = paths.path + Platform.pathSeparator + name;
|
||||
var local = paths.path + Platform.pathSeparator + name;
|
||||
|
||||
DownloaderUtils options = DownloaderUtils(
|
||||
var options = DownloaderUtils(
|
||||
progressCallback: (current, total) {
|
||||
final progress = (current / total) * 100;
|
||||
onProgress(progress);
|
||||
@ -52,7 +52,7 @@ class FileElement extends StatefulWidget {
|
||||
);
|
||||
|
||||
return await Flowder.download(
|
||||
"${await WebdavApi.webdavConnectString}$encodedPath",
|
||||
'${await WebdavApi.webdavConnectString}$encodedPath',
|
||||
options,
|
||||
);
|
||||
}
|
||||
@ -89,8 +89,7 @@ class _FileElementState extends State<FileElement> {
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListTile(
|
||||
Widget build(BuildContext context) => ListTile(
|
||||
leading: CenteredLeading(
|
||||
Icon(widget.file.isDirectory ? Icons.folder : Icons.description_outlined)
|
||||
),
|
||||
@ -100,9 +99,7 @@ class _FileElementState extends State<FileElement> {
|
||||
onTap: () {
|
||||
if(widget.file.isDirectory) {
|
||||
Navigator.of(context).push(MaterialPageRoute(
|
||||
builder: (context) {
|
||||
return Files(widget.path.toList()..add(widget.file.name));
|
||||
},
|
||||
builder: (context) => Files(widget.path.toList()..add(widget.file.name)),
|
||||
));
|
||||
} else {
|
||||
if(EndpointData().getEndpointMode() == EndpointMode.stage) {
|
||||
@ -141,12 +138,10 @@ class _FileElementState extends State<FileElement> {
|
||||
setState(() => percent = progress);
|
||||
}, (result) {
|
||||
if(result.type != ResultType.done) {
|
||||
showDialog(context: context, builder: (context) {
|
||||
return AlertDialog(
|
||||
showDialog(context: context, builder: (context) => AlertDialog(
|
||||
title: const Text('Download'),
|
||||
content: Text(result.message),
|
||||
);
|
||||
});
|
||||
));
|
||||
}
|
||||
|
||||
setState(() {
|
||||
@ -158,8 +153,7 @@ class _FileElementState extends State<FileElement> {
|
||||
}
|
||||
},
|
||||
onLongPress: () {
|
||||
showDialog(context: context, builder: (context) {
|
||||
return SimpleDialog(
|
||||
showDialog(context: context, builder: (context) => SimpleDialog(
|
||||
children: [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.delete_outline),
|
||||
@ -189,9 +183,7 @@ class _FileElementState extends State<FileElement> {
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
});
|
||||
));
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -32,18 +32,18 @@ class _FileUploadDialogState extends State<FileUploadDialog> {
|
||||
TextEditingController fileNameController = TextEditingController();
|
||||
|
||||
|
||||
void upload({bool override = false}) async {
|
||||
Future<void> upload({bool override = false}) async {
|
||||
setState(() {
|
||||
state = FileUploadState.upload;
|
||||
});
|
||||
|
||||
WebDavClient webdavClient = await WebdavApi.webdav;
|
||||
var webdavClient = await WebdavApi.webdav;
|
||||
|
||||
if(!override) {
|
||||
setState(() {
|
||||
state = FileUploadState.checkConflict;
|
||||
});
|
||||
List<WebDavResponse> result = (await webdavClient.propfind(PathUri.parse(widget.remotePath.join('/')))).responses;
|
||||
var result = (await webdavClient.propfind(PathUri.parse(widget.remotePath.join('/')))).responses;
|
||||
if(result.any((element) => element.href!.endsWith('/$targetFileName'))) {
|
||||
setState(() {
|
||||
state = FileUploadState.conflict;
|
||||
@ -56,7 +56,7 @@ class _FileUploadDialogState extends State<FileUploadDialog> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<HttpClientResponse> uploadTask = webdavClient.putFile(File(widget.localPath), FileStat.statSync(widget.localPath), PathUri.parse(fullRemotePath)); // TODO use onProgress from putFile
|
||||
var uploadTask = webdavClient.putFile(File(widget.localPath), FileStat.statSync(widget.localPath), PathUri.parse(fullRemotePath)); // TODO use onProgress from putFile
|
||||
uploadTask.then(Future<HttpClientResponse?>.value).catchError((e) {
|
||||
setState(() {
|
||||
state = FileUploadState.error;
|
||||
@ -230,4 +230,4 @@ enum FileUploadState {
|
||||
upload,
|
||||
done,
|
||||
error
|
||||
}
|
||||
}
|
||||
|
@ -64,9 +64,7 @@ class SortOptions {
|
||||
)
|
||||
};
|
||||
|
||||
static BetterSortOption getOption(SortOption option) {
|
||||
return options[option]!;
|
||||
}
|
||||
static BetterSortOption getOption(SortOption option) => options[option]!;
|
||||
}
|
||||
|
||||
class _FilesState extends State<Files> {
|
||||
@ -101,7 +99,7 @@ class _FilesState extends State<Files> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
List<CacheableFile> files = data?.sortBy(
|
||||
var files = data?.sortBy(
|
||||
sortOption: currentSort,
|
||||
foldersToTop: Provider.of<SettingsProvider>(context).val().fileSettings.sortFoldersToTop,
|
||||
reversed: currentSortDirection
|
||||
@ -119,8 +117,7 @@ class _FilesState extends State<Files> {
|
||||
// ),
|
||||
PopupMenuButton<bool>(
|
||||
icon: Icon(currentSortDirection ? Icons.text_rotate_up : Icons.text_rotation_down),
|
||||
itemBuilder: (context) {
|
||||
return [true, false].map((e) => PopupMenuItem<bool>(
|
||||
itemBuilder: (context) => [true, false].map((e) => PopupMenuItem<bool>(
|
||||
value: e,
|
||||
enabled: e != currentSortDirection,
|
||||
child: Row(
|
||||
@ -130,8 +127,7 @@ class _FilesState extends State<Files> {
|
||||
Text(e ? 'Aufsteigend' : 'Absteigend')
|
||||
],
|
||||
)
|
||||
)).toList();
|
||||
},
|
||||
)).toList(),
|
||||
onSelected: (e) {
|
||||
setState(() {
|
||||
currentSortDirection = e;
|
||||
@ -141,8 +137,7 @@ class _FilesState extends State<Files> {
|
||||
),
|
||||
PopupMenuButton<SortOption>(
|
||||
icon: const Icon(Icons.sort),
|
||||
itemBuilder: (context) {
|
||||
return SortOptions.options.keys.map((key) => PopupMenuItem<SortOption>(
|
||||
itemBuilder: (context) => SortOptions.options.keys.map((key) => PopupMenuItem<SortOption>(
|
||||
value: key,
|
||||
enabled: key != currentSort,
|
||||
child: Row(
|
||||
@ -152,8 +147,7 @@ class _FilesState extends State<Files> {
|
||||
Text(SortOptions.getOption(key).displayName)
|
||||
],
|
||||
)
|
||||
)).toList();
|
||||
},
|
||||
)).toList(),
|
||||
onSelected: (e) {
|
||||
setState(() {
|
||||
currentSort = e;
|
||||
@ -167,8 +161,7 @@ class _FilesState extends State<Files> {
|
||||
heroTag: 'uploadFile',
|
||||
backgroundColor: Theme.of(context).primaryColor,
|
||||
onPressed: () {
|
||||
showDialog(context: context, builder: (context) {
|
||||
return SimpleDialog(
|
||||
showDialog(context: context, builder: (context) => SimpleDialog(
|
||||
children: [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.create_new_folder_outlined),
|
||||
@ -224,8 +217,7 @@ class _FilesState extends State<Files> {
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
});
|
||||
));
|
||||
},
|
||||
child: const Icon(Icons.add),
|
||||
),
|
||||
@ -239,7 +231,7 @@ class _FilesState extends State<Files> {
|
||||
padding: EdgeInsets.zero,
|
||||
itemCount: files.length,
|
||||
itemBuilder: (context, index) {
|
||||
CacheableFile file = files.toList()[index];
|
||||
var file = files.toList()[index];
|
||||
return FileElement(file, widget.path, _query);
|
||||
},
|
||||
),
|
||||
@ -248,7 +240,7 @@ class _FilesState extends State<Files> {
|
||||
);
|
||||
}
|
||||
|
||||
void mediaUpload(String? path) async {
|
||||
Future<void> mediaUpload(String? path) async {
|
||||
context.loaderOverlay.hide();
|
||||
|
||||
if(path == null) {
|
||||
|
Reference in New Issue
Block a user