Initial commit
This commit is contained in:
271
lib/screen/pages/files/files.dart
Normal file
271
lib/screen/pages/files/files.dart
Normal file
@ -0,0 +1,271 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:marianum_mobile/data/incommingPackets/fileListPacket.dart';
|
||||
import 'package:marianum_mobile/widget/loadingPacket.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:webdav_client/webdav_client.dart';
|
||||
|
||||
import '../../../data/accountModel.dart';
|
||||
import '../../../widget/loadingSpinner.dart';
|
||||
|
||||
class Files extends StatefulWidget {
|
||||
const Files({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<Files> createState() => _FilesState();
|
||||
}
|
||||
|
||||
class _FilesState extends State<Files> {
|
||||
// List<String> path = List<String>.empty(growable: true);
|
||||
// List<File> files = List<File>.empty(growable: true);
|
||||
//
|
||||
// var client = newClient(
|
||||
// "https://cloud.marianum-fulda.de/remote.php/dav/files/***REMOVED***/",
|
||||
// user: "***REMOVED***",
|
||||
// password: "***REMOVED***",
|
||||
// );
|
||||
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
Provider.of<FileListPacket>(context, listen: false).invoke();
|
||||
super.initState();
|
||||
|
||||
// client.setHeaders(
|
||||
// {
|
||||
// "Authorization": "Bearer",
|
||||
// "User-Agent": "Marianum Fulda/Alpha0.1 (Development build) ; https://mhsl.eu/id.html",
|
||||
// }
|
||||
// );
|
||||
//
|
||||
// path.add("/");
|
||||
// Future.delayed(Duration.zero).then((context) => updatePath());
|
||||
}
|
||||
|
||||
// void homeFolder() {
|
||||
// path.clear();
|
||||
// path.add("/");
|
||||
// updatePath();
|
||||
// }
|
||||
//
|
||||
// void popFolder() {
|
||||
// if(path.length == 1) return;
|
||||
// path.removeLast();
|
||||
// updatePath();
|
||||
// }
|
||||
//
|
||||
// void enterFolder(String sub) {
|
||||
// path.add(sub);
|
||||
// updatePath();
|
||||
// }
|
||||
//
|
||||
// void updatePath() {
|
||||
//
|
||||
// final files = client.readDir(path.join("/"));
|
||||
//
|
||||
// showDialog(
|
||||
// context: context,
|
||||
// barrierDismissible: false,
|
||||
// builder: (BuildContext context) {
|
||||
// return const LoadingSpinner();
|
||||
// }
|
||||
// );
|
||||
//
|
||||
// files.then((value) =>
|
||||
// setState(() {
|
||||
// Navigator.pop(context);
|
||||
// this.files.clear();
|
||||
// this.files = value;
|
||||
// })
|
||||
// );
|
||||
// }
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// List<Widget> items = List<Widget>.empty(growable: true);
|
||||
//
|
||||
// var counter = 0;
|
||||
// for (final file in files) {
|
||||
// bool isDir = file.isDir ?? false;
|
||||
// String name = file.name ?? "?";
|
||||
//
|
||||
// items.add(ListTile(
|
||||
// title: Text(file.name ?? "?"),
|
||||
// leading: Icon(isDir ? Icons.folder_outlined : Icons.file_copy),
|
||||
// trailing: Icon(isDir ? Icons.arrow_right : null),
|
||||
// onTap: () {
|
||||
// enterFolder(file.name ?? "");
|
||||
// },
|
||||
// onLongPress: () {
|
||||
// setState(() {
|
||||
// items[counter] = ListTile(
|
||||
// title: Text(file.name ?? "?"),
|
||||
// trailing: const Icon(Icons.delete),
|
||||
// );
|
||||
// });
|
||||
// },
|
||||
// ));
|
||||
//
|
||||
// }
|
||||
//
|
||||
// items.insert(0, AppBar(
|
||||
// leading: path.length == 1 ? null : IconButton(
|
||||
// icon: const Icon(Icons.keyboard_arrow_left),
|
||||
// onPressed: () {
|
||||
// popFolder();
|
||||
// },
|
||||
// ),
|
||||
// actions: [
|
||||
// IconButton(
|
||||
// icon: const Icon(Icons.home),
|
||||
// onPressed: () {
|
||||
// homeFolder();
|
||||
// },
|
||||
// ),
|
||||
//
|
||||
// IconButton(
|
||||
// icon: const Icon(Icons.refresh),
|
||||
// onPressed: () {
|
||||
// updatePath();
|
||||
// },
|
||||
// )
|
||||
// ],
|
||||
//
|
||||
// title: Text(path.length == 1 ? "Dateien" : path.last),
|
||||
// ));
|
||||
//
|
||||
// return ListView(
|
||||
// children: items,
|
||||
// );
|
||||
|
||||
return Consumer<FileListPacket>(
|
||||
builder: (context, data, child) {
|
||||
List<ListTile> entries = List<ListTile>.empty(growable: true);
|
||||
|
||||
data.entries.forEach((element) {
|
||||
entries.add(ListTile(
|
||||
title: Text(element.name),
|
||||
leading: Icon(element.isFolder ? Icons.folder : Icons.file_copy_outlined),
|
||||
onTap: () {
|
||||
if(element.isFolder) {
|
||||
Provider.of<FileListPacket>(context, listen: false).invoke(
|
||||
data: {
|
||||
"path": element.path
|
||||
},
|
||||
indicateLoading: true,
|
||||
);
|
||||
} else {
|
||||
// TODO: Open an File
|
||||
}
|
||||
},
|
||||
|
||||
onLongPress: () {
|
||||
showModalBottomSheet<void>(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return ListView(
|
||||
children: [
|
||||
ListTile(
|
||||
leading: Icon(Icons.delete),
|
||||
title: Text("'${element.name.replaceRange(20, element.name.length, " ...")}' Löschen"),
|
||||
),
|
||||
const ListTile(
|
||||
leading: Icon(Icons.share),
|
||||
title: Text("Teilen"),
|
||||
)
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
));
|
||||
});
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back_outlined),
|
||||
onPressed: () {
|
||||
Provider.of<FileListPacket>(context, listen: false).invoke(
|
||||
data: {
|
||||
"path": data.lastPath
|
||||
},
|
||||
indicateLoading: true,
|
||||
);
|
||||
}
|
||||
),
|
||||
|
||||
title: Text(data.lastPath),
|
||||
actions: [
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
Provider.of<FileListPacket>(context, listen: false).invoke(indicateLoading: true);
|
||||
},
|
||||
icon: const Icon(Icons.home)
|
||||
),
|
||||
PopupMenuButton(
|
||||
icon: Icon(Icons.add),
|
||||
itemBuilder: (context) {
|
||||
return [
|
||||
const PopupMenuItem<int>(
|
||||
value: 0,
|
||||
child: ListTile(
|
||||
leading: Icon(Icons.folder),
|
||||
title: Text("Ordner erstellen"),
|
||||
),
|
||||
),
|
||||
const PopupMenuItem<int>(
|
||||
value: 1,
|
||||
child: ListTile(
|
||||
leading: Icon(Icons.upload),
|
||||
title: Text("Datei Hochladen"),
|
||||
),
|
||||
)
|
||||
];
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
|
||||
floatingActionButton: FloatingActionButton.small(
|
||||
onPressed: () {
|
||||
showModalBottomSheet(
|
||||
isScrollControlled: true,
|
||||
context: context,
|
||||
backgroundColor: Colors.transparent,
|
||||
builder: (context) {
|
||||
return Container(
|
||||
height: MediaQuery.of(context).size.height * 0.3,
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft: Radius.circular(25.0),
|
||||
topRight: Radius.circular(25.0),
|
||||
)
|
||||
),
|
||||
child: ListView(
|
||||
children: const [
|
||||
ListTile(
|
||||
leading: Icon(Icons.create_new_folder_sharp),
|
||||
title: Text("Neuer Ordner"),
|
||||
),
|
||||
ListTile(
|
||||
leading: Icon(Icons.upload),
|
||||
title: Text("Hochladen"),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
backgroundColor: Theme.of(context).primaryColor,
|
||||
child: const Icon(Icons.add),
|
||||
),
|
||||
|
||||
body: LoadingPacket(packet: data, child: ListView(children: entries)),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user