64 lines
1.7 KiB
Dart
64 lines
1.7 KiB
Dart
|
|
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 '../../../data/files/filesProps.dart';
|
|
import 'fileElement.dart';
|
|
|
|
class Files extends StatefulWidget {
|
|
Function appBar;
|
|
Files(this.appBar, {Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<Files> createState() => _FilesState();
|
|
}
|
|
|
|
class _FilesState extends State<Files> {
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
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),
|
|
));
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return 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);
|
|
}
|
|
|
|
return ListView.builder(
|
|
itemCount: value.listFilesResponse.files.length,
|
|
itemBuilder: (context, index) {
|
|
CacheableFile file = value.listFilesResponse.files.skip(index).first;
|
|
return FileElement(file, updateAppBar);
|
|
},
|
|
);
|
|
}
|
|
);
|
|
}
|
|
}
|