111 lines
3.7 KiB
Dart
111 lines
3.7 KiB
Dart
|
|
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/api/marianumcloud/webdav/queries/listFiles/listFilesParams.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import '../../../api/marianumcloud/webdav/queries/listFiles/listFiles.dart';
|
|
import '../../../api/marianumcloud/webdav/queries/listFiles/listFilesResponse.dart';
|
|
import '../../../data/files/filesProps.dart';
|
|
|
|
class Files extends StatefulWidget {
|
|
const Files({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<Files> createState() => _FilesState();
|
|
}
|
|
|
|
class _FilesState extends State<Files> {
|
|
|
|
@override
|
|
void initState() {
|
|
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
|
Provider.of<FilesProps>(context, listen: false).run();
|
|
});
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
Future<ListFilesResponse> files = ListFiles(ListFilesParams("/")).run();
|
|
files.then((value) => log(value.toJson().toString()));
|
|
|
|
return Consumer<FilesProps>(
|
|
builder: (context, value, child) {
|
|
if(value.primaryLoading()) return const Center(child: CircularProgressIndicator());
|
|
|
|
return ListView.builder(
|
|
itemCount: value.listFilesResponse.files.length,
|
|
itemBuilder: (context, index) {
|
|
CacheableFile file = value.listFilesResponse.files.skip(index).first;
|
|
return ListTile(
|
|
leading: Icon(file.isDirectory ? Icons.folder : Icons.file_open_outlined),
|
|
title: Text(file.name),
|
|
subtitle: file.isDirectory ? Text("geändert ${Jiffy(file.modifiedAt).fromNow()}") : Text("${filesize(file.size)}, ${Jiffy(file.modifiedAt).fromNow()}}"),
|
|
trailing: Icon(file.isDirectory ? Icons.arrow_right : Icons.open_in_new),
|
|
onTap: () {
|
|
if(file.isDirectory) {
|
|
Provider.of<FilesProps>(context, listen: false).setPath(file.path);
|
|
}
|
|
},
|
|
);
|
|
},
|
|
);
|
|
}
|
|
);
|
|
|
|
// return Consumer<FilesProps>(
|
|
// builder: (context, data, child) {
|
|
//
|
|
// if(data.primaryLoading()) {
|
|
// return const Center(child: CircularProgressIndicator());
|
|
// }
|
|
//
|
|
// List<ListTile> entries = List<ListTile>.empty(growable: true);
|
|
//
|
|
// data.listFilesResponse.files.forEach((element) {
|
|
// entries.add(ListTile(
|
|
// title: Text(element.name ?? "?"),
|
|
// leading: Icon(element.isDir ?? false ? Icons.folder : Icons.file_copy_outlined),
|
|
// onTap: () {
|
|
// if(element.isDir ?? false) {
|
|
// // TODO: Open Folder
|
|
// } else {
|
|
// // TODO: Open an File
|
|
// }
|
|
// },
|
|
//
|
|
// onLongPress: () {
|
|
// showModalBottomSheet<void>(
|
|
// context: context,
|
|
// builder: (context) {
|
|
// return ListView(
|
|
// children: [
|
|
// ListTile(
|
|
// leading: const Icon(Icons.delete),
|
|
// title: Text("'${element.name?.replaceRange(20, element.name?.length, " ...")}' Löschen"),
|
|
// ),
|
|
// const ListTile(
|
|
// leading: Icon(Icons.share),
|
|
// title: Text("Teilen"),
|
|
// )
|
|
// ],
|
|
// );
|
|
// },
|
|
// );
|
|
// },
|
|
// ));
|
|
// });
|
|
//
|
|
// return ListView(children: entries);
|
|
// },
|
|
// );
|
|
}
|
|
}
|