File upload testing
This commit is contained in:
@ -1,11 +1,19 @@
|
||||
|
||||
import 'dart:developer';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:loader_overlay/loader_overlay.dart';
|
||||
import 'package:marianum_mobile/api/marianumcloud/webdav/queries/listFiles/cacheableFile.dart';
|
||||
import 'package:marianum_mobile/widget/errorView.dart';
|
||||
import 'package:nextcloud/nextcloud.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../../../api/marianumcloud/webdav/queries/listFiles/listFilesCache.dart';
|
||||
import '../../../api/marianumcloud/webdav/queries/listFiles/listFilesResponse.dart';
|
||||
import '../../../api/marianumcloud/webdav/webdavApi.dart';
|
||||
import '../../../data/files/filesProps.dart';
|
||||
import '../../../widget/filePick.dart';
|
||||
import 'fileElement.dart';
|
||||
|
||||
class Files extends StatefulWidget {
|
||||
@ -91,7 +99,9 @@ class _FilesState extends State<Files> {
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.search),
|
||||
onPressed: () => {},
|
||||
onPressed: () => {
|
||||
// TODO implement search
|
||||
},
|
||||
),
|
||||
PopupMenuButton<bool>(
|
||||
icon: Icon(currentSortDirection ? Icons.text_rotate_up : Icons.text_rotation_down),
|
||||
@ -137,13 +147,88 @@ class _FilesState extends State<Files> {
|
||||
),
|
||||
],
|
||||
),
|
||||
body: data == null ? const Center(child: CircularProgressIndicator()) : data!.files.isEmpty ? const ErrorView(icon: Icons.folder_off_rounded, text: "Der Ordner ist leer") : ListView.builder(
|
||||
itemCount: files.length,
|
||||
itemBuilder: (context, index) {
|
||||
CacheableFile file = files.toList().skip(index).first;
|
||||
return FileElement(file, widget.path);
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: () {
|
||||
showDialog(context: context, builder: (context) {
|
||||
return SimpleDialog(
|
||||
children: [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.folder),
|
||||
title: const Text("Neuer Ordner"),
|
||||
onTap: () {
|
||||
WebdavApi.webdav.then((webdav) {
|
||||
webdav.mkdirs("/MarianumMobileTest");
|
||||
});
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.file_open),
|
||||
title: const Text("Aus Dateien auswählen"),
|
||||
onTap: () {
|
||||
context.loaderOverlay.show();
|
||||
FilePick.documentPick().then((value) {
|
||||
log(value ?? "?");
|
||||
mediaUpload(value);
|
||||
});
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.image),
|
||||
title: const Text("Aus Gallerie auswählen"),
|
||||
onTap: () {
|
||||
context.loaderOverlay.show();
|
||||
FilePick.galleryPick().then((value) {
|
||||
log(value?.path ?? "?");
|
||||
mediaUpload(value?.path);
|
||||
});
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
});
|
||||
},
|
||||
child: const Icon(Icons.upload),
|
||||
),
|
||||
body: data == null ? const Center(child: CircularProgressIndicator()) : data!.files.isEmpty ? const ErrorView(icon: Icons.folder_off_rounded, text: "Der Ordner ist leer") : LoaderOverlay(
|
||||
child: ListView.builder(
|
||||
itemCount: files.length,
|
||||
itemBuilder: (context, index) {
|
||||
CacheableFile file = files.toList().skip(index).first;
|
||||
return FileElement(file, widget.path);
|
||||
},
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
void mediaUpload(String? path) async {
|
||||
if(path == null) {
|
||||
context.loaderOverlay.hide();
|
||||
return;
|
||||
}
|
||||
|
||||
SharedPreferences preferences = await SharedPreferences.getInstance();
|
||||
WebDavClient client = NextcloudClient("https://cloud.marianum-fulda.de/", username: preferences.getString("username"), password: preferences.getString("password"), loginName: preferences.getString("username")).webdav;
|
||||
|
||||
log("UPLOAD STARTING: $path");
|
||||
File file = File(path);
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return SimpleDialog(
|
||||
children: [
|
||||
Image.memory(file.readAsBytesSync()),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
client.upload(file.readAsBytesSync(), "/${file.path.split(Platform.pathSeparator).last}").then((value) {
|
||||
log("UPLOADED ${value.statusCode}");
|
||||
context.loaderOverlay.hide();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user