ItemView draws a set of named things as a list, a two line list, a table with sortable headers or a grid, and ItemViewModeSwitch lets whoever is looking pick. Columns drop from the end on a narrow pane before the name gets squeezed. Breadcrumb is ghost buttons with chevrons. FileDropTarget takes files dragged in from outside and shows the focus ring while one is held over it; it sits on desktop_drop, which is a new dependency. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KHotisA4hV2xmuZsHTksFX
87 lines
2.6 KiB
Dart
87 lines
2.6 KiB
Dart
import "package:cross_file/cross_file.dart";
|
|
import "package:desktop_drop/desktop_drop.dart" as dd;
|
|
import "package:flutter/widgets.dart";
|
|
|
|
import "theme/garage_theme.dart";
|
|
|
|
export "package:cross_file/cross_file.dart" show XFile;
|
|
|
|
/// Somewhere files can be dragged onto from outside the app.
|
|
///
|
|
/// Flutter has nothing for this, so its desktop_drop underneath - macOS,
|
|
/// Windows, Linux and the web. What this adds is the Garage side of it: while
|
|
/// something is being held over [child] it gets the focus ring, the same one
|
|
/// a focused field gets, because "this is where that will land" is the same
|
|
/// statement.
|
|
///
|
|
/// Folders arent walked. A dropped folder comes through [onDropFolders] as
|
|
/// its path and nothing else, so the caller decides whether thats an upload
|
|
/// of everything in it or a polite no.
|
|
class FileDropTarget extends StatefulWidget {
|
|
const FileDropTarget({
|
|
super.key,
|
|
required this.child,
|
|
required this.onDrop,
|
|
this.onDropFolders,
|
|
this.enabled = true,
|
|
});
|
|
|
|
final Widget child;
|
|
final ValueChanged<List<XFile>> onDrop;
|
|
final ValueChanged<List<String>>? onDropFolders;
|
|
|
|
/// Off, and drags pass over it as if it wasnt there.
|
|
final bool enabled;
|
|
|
|
@override
|
|
State<FileDropTarget> createState() => _FileDropTargetState();
|
|
}
|
|
|
|
class _FileDropTargetState extends State<FileDropTarget> {
|
|
bool _over = false;
|
|
|
|
void _done(dd.DropDoneDetails details) {
|
|
setState(() => _over = false);
|
|
|
|
final files = <XFile>[];
|
|
final folders = <String>[];
|
|
for (final item in details.files) {
|
|
if (item is dd.DropItemDirectory) {
|
|
folders.add(item.path);
|
|
} else {
|
|
files.add(item);
|
|
}
|
|
}
|
|
if (files.isNotEmpty) widget.onDrop(files);
|
|
if (folders.isNotEmpty) widget.onDropFolders?.call(folders);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = GarageTheme.of(context);
|
|
|
|
return dd.DropTarget(
|
|
enable: widget.enabled,
|
|
onDragEntered: (_) => setState(() => _over = true),
|
|
onDragExited: (_) => setState(() => _over = false),
|
|
onDragDone: _done,
|
|
// foreground, so the ring is drawn over the child and takes no room.
|
|
// As a border it would shove everything in by its own width the moment
|
|
// a drag came in
|
|
child: DecoratedBox(
|
|
position: DecorationPosition.foreground,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(theme.radiusSm),
|
|
border: _over
|
|
? Border.all(
|
|
color: theme.colorScheme.ring,
|
|
width: theme.density.controlBorderWidth * 2,
|
|
)
|
|
: null,
|
|
),
|
|
child: widget.child,
|
|
),
|
|
);
|
|
}
|
|
}
|