Implemented simple and basic file downloading
This commit is contained in:
parent
d519bafe3b
commit
54153f1958
.idea/libraries
lib
api/marianumcloud/webdav
queries/downloadFile
downloadFile.dartdownloadFileParams.dartdownloadFileParams.g.dartdownloadFileResponse.dartdownloadFileResponse.g.dart
webdavApi.dartdata/files
screen/pages/files
568
.idea/libraries/Dart_Packages.xml
generated
568
.idea/libraries/Dart_Packages.xml
generated
File diff suppressed because it is too large
Load Diff
42
.idea/libraries/Flutter_Plugins.xml
generated
42
.idea/libraries/Flutter_Plugins.xml
generated
@ -1,27 +1,27 @@
|
||||
<component name="libraryTable">
|
||||
<library name="Flutter Plugins" type="FlutterPluginsLibraryType">
|
||||
<CLASSES>
|
||||
<root url="file:///opt/flutter/.pub-cache/hosted/pub.dev/url_launcher_web-2.0.16" />
|
||||
<root url="file:///opt/flutter/.pub-cache/hosted/pub.dev/path_provider_windows-2.1.5" />
|
||||
<root url="file:///opt/flutter/.pub-cache/hosted/pub.dev/shared_preferences_linux-2.1.5" />
|
||||
<root url="file:///opt/flutter/.pub-cache/hosted/pub.dev/path_provider_linux-2.1.10" />
|
||||
<root url="file:///opt/flutter/.pub-cache/hosted/pub.dev/path_provider_foundation-2.1.3" />
|
||||
<root url="file:///opt/flutter/.pub-cache/hosted/pub.dev/path_provider_android-2.0.24" />
|
||||
<root url="file:///opt/flutter/.pub-cache/hosted/pub.dev/url_launcher_android-6.0.25" />
|
||||
<root url="file:///opt/flutter/.pub-cache/hosted/pub.dev/shared_preferences_foundation-2.1.5" />
|
||||
<root url="file:///opt/flutter/.pub-cache/hosted/pub.dev/shared_preferences_windows-2.1.5" />
|
||||
<root url="file:///opt/flutter/.pub-cache/hosted/pub.dev/url_launcher_macos-3.0.4" />
|
||||
<root url="file:///opt/flutter/.pub-cache/hosted/pub.dev/shared_preferences_web-2.0.6" />
|
||||
<root url="file:///opt/flutter/.pub-cache/hosted/pub.dev/url_launcher_windows-3.0.5" />
|
||||
<root url="file:///opt/flutter/.pub-cache/hosted/pub.dev/url_launcher_ios-6.1.2" />
|
||||
<root url="file:///opt/flutter/.pub-cache/hosted/pub.dev/url_launcher_linux-3.0.4" />
|
||||
<root url="file:///opt/flutter/.pub-cache/hosted/pub.dev/shared_preferences_android-2.0.17" />
|
||||
<root url="file:///opt/flutter/.pub-cache/hosted/pub.dev/shared_preferences-2.0.18" />
|
||||
<root url="file:///opt/flutter/.pub-cache/hosted/pub.dev/path_provider-2.0.13" />
|
||||
<root url="file:///opt/flutter/.pub-cache/hosted/pub.dev/sqflite-2.2.5" />
|
||||
<root url="file:///opt/flutter/.pub-cache/hosted/pub.dev/open_file-2.1.1" />
|
||||
<root url="file:///opt/flutter/.pub-cache/hosted/pub.dev/flutter_native_splash-2.2.16" />
|
||||
<root url="file:///opt/flutter/.pub-cache/hosted/pub.dev/url_launcher-6.1.10" />
|
||||
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dev/url_launcher_web-2.0.16" />
|
||||
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dev/url_launcher_android-6.0.25" />
|
||||
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dev/url_launcher_linux-3.0.4" />
|
||||
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dev/shared_preferences-2.0.18" />
|
||||
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dev/url_launcher_macos-3.0.4" />
|
||||
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dev/path_provider_android-2.0.24" />
|
||||
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dev/url_launcher_windows-3.0.5" />
|
||||
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dev/url_launcher_ios-6.1.2" />
|
||||
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dev/path_provider_foundation-2.1.3" />
|
||||
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dev/path_provider_linux-2.1.10" />
|
||||
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dev/url_launcher-6.1.10" />
|
||||
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dev/shared_preferences_linux-2.1.5" />
|
||||
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dev/shared_preferences_foundation-2.1.5" />
|
||||
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dev/sqflite-2.2.5" />
|
||||
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dev/shared_preferences_android-2.0.17" />
|
||||
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dev/path_provider_windows-2.1.5" />
|
||||
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dev/shared_preferences_windows-2.1.5" />
|
||||
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dev/path_provider-2.0.13" />
|
||||
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dev/shared_preferences_web-2.0.6" />
|
||||
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dev/better_open_file-3.6.4" />
|
||||
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dev/flutter_native_splash-2.2.19" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
|
@ -0,0 +1,21 @@
|
||||
|
||||
import 'package:marianum_mobile/api/apiResponse.dart';
|
||||
import 'package:marianum_mobile/api/marianumcloud/webdav/queries/downloadFile/downloadFileParams.dart';
|
||||
import 'package:marianum_mobile/api/marianumcloud/webdav/webdavApi.dart';
|
||||
|
||||
class DownloadFile extends WebdavApi<DownloadFileParams> {
|
||||
DownloadFileParams params;
|
||||
|
||||
DownloadFile(this.params) : super(params);
|
||||
|
||||
@override
|
||||
Future<ApiResponse> run() async {
|
||||
|
||||
// final file = await File(localPath).create();
|
||||
// Uint8List downloadedFile = await (await WebdavApi.webdav).download(params.webdavPath);
|
||||
// file.writeAsBytesSync(downloadedFile, flush: true, mode: FileMode.write);
|
||||
//
|
||||
// OpenFile.open(localPath);
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:marianum_mobile/api/apiParams.dart';
|
||||
|
||||
part 'downloadFileParams.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class DownloadFileParams extends ApiParams {
|
||||
String webdavSourcePath;
|
||||
String localTargetPath;
|
||||
String filename;
|
||||
|
||||
DownloadFileParams(this.webdavSourcePath, this.localTargetPath, this.filename);
|
||||
|
||||
factory DownloadFileParams.fromJson(Map<String, dynamic> json) => _$DownloadFileParamsFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$DownloadFileParamsToJson(this);
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'downloadFileParams.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
DownloadFileParams _$DownloadFileParamsFromJson(Map<String, dynamic> json) =>
|
||||
DownloadFileParams(
|
||||
json['webdavSourcePath'] as String,
|
||||
json['localTargetPath'] as String,
|
||||
json['filename'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$DownloadFileParamsToJson(DownloadFileParams instance) =>
|
||||
<String, dynamic>{
|
||||
'webdavSourcePath': instance.webdavSourcePath,
|
||||
'localTargetPath': instance.localTargetPath,
|
||||
'filename': instance.filename,
|
||||
};
|
@ -0,0 +1,14 @@
|
||||
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'downloadFileResponse.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class DownloadFileResponse {
|
||||
String path;
|
||||
|
||||
DownloadFileResponse(this.path);
|
||||
|
||||
factory DownloadFileResponse.fromJson(Map<String, dynamic> json) => _$DownloadFileResponseFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$DownloadFileResponseToJson(this);
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'downloadFileResponse.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
DownloadFileResponse _$DownloadFileResponseFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
DownloadFileResponse(
|
||||
json['path'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$DownloadFileResponseToJson(
|
||||
DownloadFileResponse instance) =>
|
||||
<String, dynamic>{
|
||||
'path': instance.path,
|
||||
};
|
@ -14,10 +14,17 @@ abstract class WebdavApi<T> extends ApiRequest {
|
||||
Future<ApiResponse> run();
|
||||
|
||||
static Future<WebDavClient> webdav = establishWebdavConnection();
|
||||
static Future<String> webdavConnectString = buildWebdavConnectString();
|
||||
|
||||
static Future<WebDavClient> establishWebdavConnection() async {
|
||||
SharedPreferences preferences = await SharedPreferences.getInstance();
|
||||
|
||||
return NextcloudClient("https://cloud.marianum-fulda.de/", username: preferences.getString("username"), password: preferences.getString("password"), loginName: preferences.getString("username")).webdav;
|
||||
}
|
||||
|
||||
static Future<String> buildWebdavConnectString() async {
|
||||
SharedPreferences preferences = await SharedPreferences.getInstance();
|
||||
|
||||
return "https://${preferences.getString("username")}:${preferences.getString("password")}@cloud.marianum-fulda.de/remote.php/dav/files/${preferences.getString("username")}/";
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
|
||||
import 'package:marianum_mobile/api/apiResponse.dart';
|
||||
import 'package:marianum_mobile/api/marianumcloud/webdav/queries/listFiles/listFilesCache.dart';
|
||||
import 'package:marianum_mobile/api/marianumcloud/webdav/queries/listFiles/listFilesResponse.dart';
|
||||
|
89
lib/screen/pages/files/fileDownload.dart
Normal file
89
lib/screen/pages/files/fileDownload.dart
Normal file
@ -0,0 +1,89 @@
|
||||
import 'dart:developer';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flowder/flowder.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:marianum_mobile/api/marianumcloud/webdav/webdavApi.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
class FileDownload extends StatefulWidget {
|
||||
String source;
|
||||
String name;
|
||||
FileDownload(this.source, this.name, {Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<FileDownload> createState() => _FileDownloadState();
|
||||
}
|
||||
|
||||
class _FileDownloadState extends State<FileDownload> {
|
||||
late DownloaderCore core;
|
||||
|
||||
void download(String remotePath, String name) async {
|
||||
List<Directory>? paths = await getExternalStorageDirectories(type: StorageDirectory.downloads);
|
||||
|
||||
String local = paths!.first.path + Platform.pathSeparator + name;
|
||||
|
||||
DownloaderUtils options = DownloaderUtils(
|
||||
progressCallback: (current, total) {
|
||||
final progress = (current / total) * 100;
|
||||
setState(() => {
|
||||
percent = progress,
|
||||
});
|
||||
},
|
||||
file: File(local),
|
||||
progress: ProgressImplementation(),
|
||||
deleteOnCancel: true,
|
||||
onDone: () {
|
||||
// OpenFile.open(local).then((value) => () {
|
||||
// log("Result: ${value.toString()}");
|
||||
// });
|
||||
Navigator.of(context).pop();
|
||||
showDialog(context: context, builder: (context) {
|
||||
return AlertDialog(
|
||||
icon: const Icon(Icons.link),
|
||||
title: const Text("Dateipfad"),
|
||||
content: Text(local),
|
||||
);
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
log(local);
|
||||
|
||||
core = await Flowder.download(
|
||||
"${await WebdavApi.webdavConnectString}$remotePath",
|
||||
options,
|
||||
);
|
||||
}
|
||||
|
||||
double percent = 0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
log("Downloading file: Source(${widget.source}), Name(${widget.name})");
|
||||
download(widget.source, widget.name);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text("Download"),
|
||||
content: ListTile(
|
||||
leading: const Icon(Icons.download),
|
||||
title: LinearProgressIndicator(value: percent/100),
|
||||
trailing: Text("${percent.round()}%"),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: const Text("Abbrechen"),
|
||||
onPressed: () => () {
|
||||
if(!core.isCancelled) core.cancel();
|
||||
Navigator.of(context, rootNavigator: true).pop();
|
||||
},
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
@ -1,7 +1,10 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:filesize/filesize.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:jiffy/jiffy.dart';
|
||||
import 'package:marianum_mobile/api/marianumcloud/webdav/queries/listFiles/cacheableFile.dart';
|
||||
import 'package:marianum_mobile/screen/pages/files/fileDownload.dart';
|
||||
import 'package:marianum_mobile/widget/errorView.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
@ -66,11 +69,10 @@ class _FilesState extends State<Files> {
|
||||
props.enterFolder(file.name);
|
||||
} else {
|
||||
//TODO implement file download / view
|
||||
log(file.path);
|
||||
|
||||
showDialog(context: context, builder: (context) {
|
||||
return const AlertDialog(
|
||||
title: Text("Datei öffnen"),
|
||||
content: Text("Das öffnen von Dateien ist noch nicht implementiert!"),
|
||||
);
|
||||
return FileDownload(file.path, file.name);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
@ -51,14 +51,17 @@ dependencies:
|
||||
git:
|
||||
url: https://github.com/provokateurin/nextcloud-neon
|
||||
path: packages/nextcloud
|
||||
flutter_launcher_icons: ^0.11.0
|
||||
flutter_launcher_icons: ^0.12.0
|
||||
pretty_json: ^2.0.0
|
||||
cached_network_image: ^3.2.3
|
||||
open_file: ^2.1.1
|
||||
flowder: ^0.2.0
|
||||
url_launcher: ^6.1.10
|
||||
flutter_linkify: ^5.0.2
|
||||
filesize: ^2.0.1
|
||||
path_provider: ^2.0.13
|
||||
better_open_file: ^3.6.4
|
||||
flowder:
|
||||
git:
|
||||
url: https://github.com/Harsh223/flowder.git
|
||||
|
||||
dependency_overrides:
|
||||
xml: ^6.2.2
|
||||
|
Loading…
x
Reference in New Issue
Block a user