WIP: File Browsing with Backbutton
This commit is contained in:
@ -1,43 +1,41 @@
|
||||
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:marianum_mobile/api/marianumcloud/webdav/queries/listFiles/cacheableFile.dart';
|
||||
import 'package:marianum_mobile/widget/errorView.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../../api/marianumcloud/webdav/queries/listFiles/listFilesCache.dart';
|
||||
import '../../../api/marianumcloud/webdav/queries/listFiles/listFilesResponse.dart';
|
||||
import '../../../data/files/filesProps.dart';
|
||||
import 'fileElement.dart';
|
||||
|
||||
class Files extends StatefulWidget {
|
||||
Function appBar;
|
||||
Files(this.appBar, {Key? key}) : super(key: key);
|
||||
List<String> path;
|
||||
Files(this.path, {Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<Files> createState() => _FilesState();
|
||||
}
|
||||
|
||||
class _FilesState extends State<Files> {
|
||||
FilesProps props = FilesProps();
|
||||
ListFilesResponse? data;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
log("Init files: ${widget.path.toString()}");
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
||||
Provider.of<FilesProps>(context, listen: false).run();
|
||||
});
|
||||
}
|
||||
|
||||
void updateAppBar(FilesProps props) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
||||
widget.appBar(context, AppBar(
|
||||
leading: BackButton(
|
||||
onPressed: () {
|
||||
updateAppBar(props);
|
||||
props.popFolder();
|
||||
},
|
||||
),
|
||||
title: Text(props.currentFolderName),
|
||||
));
|
||||
});
|
||||
ListFilesCache(
|
||||
path: widget.path.isEmpty ? "/" : widget.path.join("/"),
|
||||
onUpdate: (ListFilesResponse d) => {
|
||||
setState(() {
|
||||
data = d;
|
||||
}),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
@ -56,26 +54,32 @@ class _FilesState extends State<Files> {
|
||||
)
|
||||
],
|
||||
),
|
||||
body: Consumer<FilesProps>(
|
||||
builder: (context, value, child) {
|
||||
if(value.primaryLoading()) return const Center(child: CircularProgressIndicator());
|
||||
|
||||
if(value.listFilesResponse.files.isEmpty) {
|
||||
return const ErrorView(text: "Der Ordner ist leer", icon: Icons.folder_off_outlined);
|
||||
}
|
||||
|
||||
List<CacheableFile> files = value.listFilesResponse.files.toList();
|
||||
files.sort((a, b) => a.isDirectory ? -1 : 1);
|
||||
|
||||
return ListView.builder(
|
||||
itemCount: files.length,
|
||||
itemBuilder: (context, index) {
|
||||
CacheableFile file = files.skip(index).first;
|
||||
return FileElement(file, updateAppBar);
|
||||
},
|
||||
);
|
||||
}
|
||||
),
|
||||
body: data == null ? Center(child: CircularProgressIndicator()) : ListView.builder(
|
||||
itemCount: data!.files.toList().length,
|
||||
itemBuilder: (context, index) {
|
||||
CacheableFile file = data!.files.toList().skip(index).first;
|
||||
return FileElement(file, widget.path);
|
||||
},
|
||||
),
|
||||
// Consumer<FilesProps>(
|
||||
// builder: (context, value, child) {
|
||||
//
|
||||
// if(value.listFilesResponse.files.isEmpty) {
|
||||
// return const ErrorView(text: "Der Ordner ist leer", icon: Icons.folder_off_outlined);
|
||||
// }
|
||||
//
|
||||
// List<CacheableFile> files = value.listFilesResponse.files.toList();
|
||||
// files.sort((a, b) => a.isDirectory ? -1 : 1);
|
||||
//
|
||||
// return ListView.builder(
|
||||
// itemCount: files.length,
|
||||
// itemBuilder: (context, index) {
|
||||
// CacheableFile file = files.skip(index).first;
|
||||
// return FileElement(file, props);
|
||||
// },
|
||||
// );
|
||||
// }
|
||||
// ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user