added upload with multiple files
This commit is contained in:
@ -1,10 +1,9 @@
|
||||
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:loader_overlay/loader_overlay.dart';
|
||||
import 'package:nextcloud/nextcloud.dart';
|
||||
import 'package:persistent_bottom_nav_bar_v2/persistent_bottom_nav_bar_v2.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
import '../../../../api/marianumcloud/files-sharing/fileSharingApi.dart';
|
||||
import '../../../../api/marianumcloud/files-sharing/fileSharingApiParams.dart';
|
||||
@ -15,7 +14,7 @@ import '../../../../model/chatList/chatProps.dart';
|
||||
import '../../../../storage/base/settingsProvider.dart';
|
||||
import '../../../../widget/filePick.dart';
|
||||
import '../../../../widget/focusBehaviour.dart';
|
||||
import '../../files/fileUploadDialog.dart';
|
||||
import '../../files/filesUploadDialog.dart';
|
||||
|
||||
class ChatTextfield extends StatefulWidget {
|
||||
final String sendToToken;
|
||||
@ -34,34 +33,40 @@ class _ChatTextfieldState extends State<ChatTextfield> {
|
||||
Provider.of<ChatProps>(context, listen: false).run();
|
||||
}
|
||||
|
||||
void mediaUpload(String? path) async {
|
||||
context.loaderOverlay.hide();
|
||||
|
||||
if(path == null) {
|
||||
return;
|
||||
void share(String shareFolder, List<String> filePaths) {
|
||||
for (var element in filePaths) {
|
||||
String fileName = element.split(Platform.pathSeparator).last;
|
||||
FileSharingApi().share(FileSharingApiParams(
|
||||
shareType: 10,
|
||||
shareWith: widget.sendToToken,
|
||||
path: '$shareFolder/$fileName',
|
||||
)).then((value) => _query());
|
||||
}
|
||||
}
|
||||
|
||||
void mediaUpload(List<String>? paths) async {
|
||||
if (paths == null) return;
|
||||
|
||||
String filename = "${path.split("/").last.split(".").first}-${const Uuid().v4()}.${path.split(".").last}";
|
||||
String shareFolder = 'MarianumMobile';
|
||||
WebdavApi.webdav.then((webdav) {
|
||||
webdav.mkcol(PathUri.parse('/$shareFolder'));
|
||||
});
|
||||
|
||||
showDialog(context: context, builder: (context) => FileUploadDialog(
|
||||
doShowFinish: false,
|
||||
fileName: filename,
|
||||
localPath: path,
|
||||
remotePath: [shareFolder],
|
||||
onUploadFinished: () {
|
||||
FileSharingApi().share(FileSharingApiParams(
|
||||
shareType: 10,
|
||||
shareWith: widget.sendToToken,
|
||||
path: '$shareFolder/$filename',
|
||||
)).then((value) => _query());
|
||||
},
|
||||
), barrierDismissible: false);
|
||||
pushScreen(
|
||||
context,
|
||||
withNavBar: false,
|
||||
screen: FilesUploadDialog(
|
||||
filePaths: paths,
|
||||
remotePath: shareFolder,
|
||||
onUploadFinished: (uploadedFilePaths) {
|
||||
share(shareFolder, uploadedFilePaths);
|
||||
},
|
||||
uniqueNames: true,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void setDraft(String text) {
|
||||
if(text.isNotEmpty) {
|
||||
settings.val(write: true).talkSettings.drafts[widget.sendToToken] = text;
|
||||
@ -98,7 +103,6 @@ class _ChatTextfieldState extends State<ChatTextfield> {
|
||||
leading: const Icon(Icons.file_open),
|
||||
title: const Text('Aus Dateien auswählen'),
|
||||
onTap: () {
|
||||
context.loaderOverlay.show();
|
||||
FilePick.documentPick().then(mediaUpload);
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
@ -109,9 +113,8 @@ class _ChatTextfieldState extends State<ChatTextfield> {
|
||||
leading: const Icon(Icons.image),
|
||||
title: const Text('Aus Gallerie auswählen'),
|
||||
onTap: () {
|
||||
context.loaderOverlay.show();
|
||||
FilePick.galleryPick().then((value) {
|
||||
mediaUpload(value?.path);
|
||||
if(value != null) mediaUpload([value.path]);
|
||||
});
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
|
Reference in New Issue
Block a user