2022-12-13 09:34:14 +00:00
|
|
|
// @dart=2.9
|
|
|
|
|
2022-12-22 04:48:06 +00:00
|
|
|
import 'package:flutter/foundation.dart';
|
2022-12-13 09:34:14 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2022-12-22 04:48:06 +00:00
|
|
|
import 'package:flutter/services.dart';
|
2022-12-13 09:34:14 +00:00
|
|
|
import 'package:photos/theme/ente_theme.dart';
|
|
|
|
import 'package:photos/ui/common/loading_widget.dart';
|
|
|
|
import 'package:photos/ui/components/captioned_text_widget.dart';
|
|
|
|
import 'package:photos/ui/components/menu_item_widget.dart';
|
|
|
|
import 'package:photos/utils/app_size.dart';
|
|
|
|
import 'package:photos/utils/data_util.dart';
|
|
|
|
|
2022-12-22 04:48:06 +00:00
|
|
|
class PathStorageItem {
|
2022-12-13 09:34:14 +00:00
|
|
|
final String path;
|
2022-12-22 04:48:06 +00:00
|
|
|
final String title;
|
|
|
|
final bool allowCacheClear;
|
|
|
|
|
|
|
|
PathStorageItem.name(
|
|
|
|
this.path,
|
|
|
|
this.title, {
|
|
|
|
this.allowCacheClear = false,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
class PathStorageViewer extends StatefulWidget {
|
|
|
|
final PathStorageItem path;
|
2022-12-13 09:34:14 +00:00
|
|
|
|
|
|
|
const PathStorageViewer(
|
|
|
|
this.path, {
|
|
|
|
Key key,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<PathStorageViewer> createState() => _PathStorageViewerState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _PathStorageViewerState extends State<PathStorageViewer> {
|
|
|
|
Map<String, int> _logs;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
2022-12-22 04:48:06 +00:00
|
|
|
directoryStat(widget.path.path).then((logs) {
|
2022-12-13 09:34:14 +00:00
|
|
|
setState(() {
|
|
|
|
_logs = logs;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return _getBody();
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _getBody() {
|
|
|
|
if (_logs == null) {
|
|
|
|
return const EnteLoadingWidget();
|
|
|
|
}
|
|
|
|
final int fileCount = _logs["fileCount"] ?? -1;
|
|
|
|
final int size = _logs['size'];
|
|
|
|
|
2022-12-22 04:48:06 +00:00
|
|
|
return MenuItemWidget(
|
|
|
|
alignCaptionedTextToLeft: true,
|
|
|
|
captionedTextWidget: CaptionedTextWidget(
|
|
|
|
title: widget.path.title,
|
|
|
|
subTitle: '$fileCount',
|
|
|
|
subTitleColor: getEnteColorScheme(context).textFaint,
|
|
|
|
),
|
|
|
|
trailingWidget: Text(
|
|
|
|
formatBytes(size),
|
|
|
|
style: getEnteTextTheme(context)
|
|
|
|
.small
|
|
|
|
.copyWith(color: getEnteColorScheme(context).textFaint),
|
2022-12-13 09:34:14 +00:00
|
|
|
),
|
2022-12-22 04:48:06 +00:00
|
|
|
trailingIcon: widget.path.allowCacheClear ? Icons.chevron_right : null,
|
|
|
|
menuItemColor: getEnteColorScheme(context).fillFaint,
|
|
|
|
onTap: () async {
|
|
|
|
if (kDebugMode) {
|
|
|
|
await Clipboard.setData(ClipboardData(text: widget.path.path));
|
|
|
|
debugPrint(widget.path.path);
|
|
|
|
}
|
|
|
|
},
|
2022-12-13 09:34:14 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|