58 lines
2.2 KiB
Dart
58 lines
2.2 KiB
Dart
import 'dart:developer';
|
|
|
|
import 'package:filesize/filesize.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:jiffy/jiffy.dart';
|
|
|
|
import '../../../../../widget/centeredLeading.dart';
|
|
import '../../../../../widget/list_view_util.dart';
|
|
import '../../../infrastructure/loadableState/view/loadable_state_consumer.dart';
|
|
import '../bloc/files_bloc.dart';
|
|
import '../bloc/files_event.dart';
|
|
import '../bloc/files_state.dart';
|
|
|
|
class FolderView extends StatelessWidget {
|
|
final FilesBloc bloc;
|
|
const FolderView(this.bloc, {super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) => Scaffold(
|
|
appBar: AppBar(
|
|
leading: !bloc.canGoBack() ? null : IconButton(
|
|
icon: const Icon(Icons.arrow_back),
|
|
onPressed: () {
|
|
bloc.add(EnterFolder(bloc.goBackLocation()));
|
|
Navigator.of(context).pop();
|
|
},
|
|
),
|
|
title: Text(bloc.getCurrentFolderName()),
|
|
|
|
actions: [
|
|
IconButton(onPressed: () {
|
|
log(bloc.innerState?.toJson().toString() ?? 'leer');
|
|
}, icon: const Icon(Icons.bug_report)),
|
|
IconButton(onPressed: () {
|
|
bloc.add(EnterFolder('/'));
|
|
}, icon: const Icon(Icons.home)),
|
|
],
|
|
),
|
|
body: LoadableStateConsumer<FilesBloc, FilesState>(
|
|
controllerByValue: bloc,
|
|
child: (state, loading) => ListViewUtil.fromList<File>(bloc.getVisibleFiles(), (file) => ListTile(
|
|
leading: CenteredLeading(Icon(file.isFolder ? Icons.folder : Icons.description_outlined)),
|
|
title: Text(file.name),
|
|
subtitle: file.isFolder
|
|
? Text('geändert ${Jiffy.parseFromDateTime(file.updatedAt ?? DateTime.now()).fromNow()}')
|
|
: Text('${filesize(file.size)}, ${Jiffy.parseFromDateTime(file.updatedAt ?? DateTime.now()).fromNow()}'),
|
|
trailing: Icon(file.isFolder ? Icons.arrow_right : null),
|
|
onTap: () {
|
|
log(file.path);
|
|
if(!file.isFolder) return;
|
|
Navigator.of(context).push(MaterialPageRoute(builder: (context) => FolderView(bloc)));
|
|
bloc.add(EnterFolder(file.path));
|
|
},
|
|
))
|
|
)
|
|
);
|
|
}
|