Minor fixes for file download handling
This commit is contained in:
@ -20,16 +20,7 @@ class FileElement extends StatefulWidget {
|
||||
List<String> path;
|
||||
FileElement(this.file, this.path, {Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<FileElement> createState() => _FileElementState();
|
||||
}
|
||||
|
||||
class _FileElementState extends State<FileElement> {
|
||||
late DownloaderCore core;
|
||||
double percent = 0;
|
||||
|
||||
void download(String remotePath, String name) async {
|
||||
|
||||
static void download(String remotePath, String name, Function(double) onProgress, Function(OpenResult) onDone) async {
|
||||
Directory paths = await getApplicationDocumentsDirectory();
|
||||
|
||||
String local = paths.path + Platform.pathSeparator + name;
|
||||
@ -37,9 +28,7 @@ class _FileElementState extends State<FileElement> {
|
||||
DownloaderUtils options = DownloaderUtils(
|
||||
progressCallback: (current, total) {
|
||||
final progress = (current / total) * 100;
|
||||
setState(() => {
|
||||
percent = progress,
|
||||
});
|
||||
onProgress(progress);
|
||||
},
|
||||
file: File(local),
|
||||
progress: ProgressImplementation(),
|
||||
@ -48,29 +37,26 @@ class _FileElementState extends State<FileElement> {
|
||||
Future<OpenResult> result = OpenFile.open(local);
|
||||
|
||||
result.then((value) => {
|
||||
if(value.type != ResultType.done) {
|
||||
showDialog(context: context, builder: (context) {
|
||||
return AlertDialog(
|
||||
title: Text("Download"),
|
||||
content: Text(value.message),
|
||||
);
|
||||
})
|
||||
}
|
||||
onDone(value)
|
||||
});
|
||||
|
||||
widget.file.currentlyDownloading = false;
|
||||
percent = 0;
|
||||
},
|
||||
);
|
||||
|
||||
log(local);
|
||||
|
||||
core = await Flowder.download(
|
||||
await Flowder.download(
|
||||
"${await WebdavApi.webdavConnectString}$remotePath",
|
||||
options,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
State<FileElement> createState() => _FileElementState();
|
||||
}
|
||||
|
||||
class _FileElementState extends State<FileElement> {
|
||||
double percent = 0;
|
||||
|
||||
Widget getSubtitle() {
|
||||
if(widget.file.currentlyDownloading) {
|
||||
return Row(
|
||||
@ -114,7 +100,25 @@ class _FileElementState extends State<FileElement> {
|
||||
|
||||
log("Download: ${widget.file.path} to ${widget.file.name}");
|
||||
|
||||
download(widget.file.path, widget.file.name);
|
||||
FileElement.download(widget.file.path, widget.file.name, (progress) {
|
||||
setState(() => {
|
||||
percent = progress,
|
||||
});
|
||||
}, (result) {
|
||||
if(result.type != ResultType.done) {
|
||||
showDialog(context: context, builder: (context) {
|
||||
return AlertDialog(
|
||||
title: Text("Download"),
|
||||
content: Text(result.message),
|
||||
);
|
||||
});
|
||||
|
||||
setState(() {
|
||||
widget.file.currentlyDownloading = false;
|
||||
percent = 0;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
},
|
||||
|
Reference in New Issue
Block a user