2 Commits

3 changed files with 144 additions and 0 deletions
+20
View File
@@ -0,0 +1,20 @@
import 'dart:async';
/// App-wide pub/sub channel for cache invalidations. Producers (e.g. webdav
/// move/delete handlers) call [notifyListFiles] after they have dropped the
/// cached listing for a folder so that any [_FilesView] currently sitting on
/// that folder — possibly in the background, beneath a child route — can
/// refresh itself instead of showing the stale snapshot it loaded earlier.
class CacheInvalidationBus {
CacheInvalidationBus._();
static final StreamController<String> _listFiles = StreamController<String>.broadcast();
/// Emits the invalidated `pathString` (in `FilesBloc` format: relative,
/// no leading or trailing slash; root is '/').
static Stream<String> get listFilesStream => _listFiles.stream;
static void notifyListFiles(String pathString) {
_listFiles.add(pathString);
}
}
+44
View File
@@ -0,0 +1,44 @@
import 'package:flutter/foundation.dart';
import '../api/marianumcloud/webdav/queries/list_files/cacheable_file.dart';
enum FileClipboardOperation { cut, copy }
/// In-memory clipboard for file operations within the app. Mirrors the
/// cut/copy/paste pattern of native file managers (iOS Files, Android Files,
/// Finder). Contents are not persisted across app restarts.
///
/// Listen via [ChangeNotifier] (e.g. `ListenableBuilder`) to render a paste
/// banner when [isEmpty] is false.
class FileClipboard extends ChangeNotifier {
FileClipboard._();
static final FileClipboard instance = FileClipboard._();
FileClipboardOperation? _operation;
List<CacheableFile> _files = const [];
FileClipboardOperation? get operation => _operation;
List<CacheableFile> get files => List.unmodifiable(_files);
bool get isEmpty => _files.isEmpty;
void cut(List<CacheableFile> files) {
if (files.isEmpty) return;
_operation = FileClipboardOperation.cut;
_files = List.of(files);
notifyListeners();
}
void copy(List<CacheableFile> files) {
if (files.isEmpty) return;
_operation = FileClipboardOperation.copy;
_files = List.of(files);
notifyListeners();
}
void clear() {
if (_operation == null && _files.isEmpty) return;
_operation = null;
_files = const [];
notifyListeners();
}
}
@@ -0,0 +1,80 @@
import 'package:filesize/filesize.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:jiffy/jiffy.dart';
import '../../../../api/marianumcloud/webdav/queries/list_files/cacheable_file.dart';
/// Shows a modal bottom sheet with technical metadata about a single file or
/// folder: full path, MIME type, size, timestamps, ETag.
Future<void> showFileDetailsSheet(BuildContext context, CacheableFile file) {
return showModalBottomSheet<void>(
context: context,
isScrollControlled: true,
showDragHandle: true,
builder: (context) => SafeArea(
child: SingleChildScrollView(
padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
children: [
ListTile(
leading: Icon(file.isDirectory ? Icons.folder : Icons.description_outlined, size: 32),
title: Text(file.name, style: const TextStyle(fontWeight: FontWeight.bold)),
subtitle: Text(file.isDirectory ? 'Ordner' : (file.mimeType ?? '')),
),
const Divider(),
_DetailRow(label: 'Pfad', value: file.path, copyable: true),
if (!file.isDirectory) _DetailRow(label: 'Größe', value: filesize(file.size)),
if (file.modifiedAt != null)
_DetailRow(
label: 'Geändert',
value: '${Jiffy.parseFromDateTime(file.modifiedAt!).format(pattern: 'dd.MM.yyyy HH:mm')} '
'(${Jiffy.parseFromDateTime(file.modifiedAt!).fromNow()})',
),
if (file.createdAt != null)
_DetailRow(
label: 'Erstellt',
value: Jiffy.parseFromDateTime(file.createdAt!).format(pattern: 'dd.MM.yyyy HH:mm'),
),
if (file.eTag != null) _DetailRow(label: 'ETag', value: file.eTag!, copyable: true),
],
),
),
),
);
}
class _DetailRow extends StatelessWidget {
const _DetailRow({required this.label, required this.value, this.copyable = false});
final String label;
final String value;
final bool copyable;
@override
Widget build(BuildContext context) => Padding(
padding: const EdgeInsets.symmetric(vertical: 6),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
width: 90,
child: Text(label, style: TextStyle(color: Theme.of(context).colorScheme.onSurfaceVariant)),
),
Expanded(child: SelectableText(value)),
if (copyable)
IconButton(
tooltip: 'Kopieren',
icon: const Icon(Icons.copy, size: 18),
onPressed: () {
Clipboard.setData(ClipboardData(text: value));
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('In Zwischenablage kopiert')),
);
},
),
],
),
);
}