Files
pipelines/app/lib/features/chat/files/files_entries.dart
T
alan b8fb4d350c Upload files into the shown folder from the chat Files panel
The header gains an Upload button that uses the host file picker (disabled
with its reason where no picker exists), and the panel body becomes a drop
target: on web, document drag events are observed through a dart:js_interop
seam and a file drag over the panel shows a highlight naming the folder.
Each file is posted to POST /files?path=<folder> through an injectable
transport; refusals (exists, sign in, too large) stay visible until dismissed
and the folder reloads afterwards. The list/grid builders move to
files_entries.dart to keep the panel small.
2026-11-09 00:09:01 +00:00

92 lines
2.7 KiB
Dart

import 'package:flutter/material.dart';
import '../data/directory_listing.dart';
import 'files_icons.dart';
import 'files_models.dart';
import 'files_thumbnail.dart';
/// The folder's entries as the list or the thumbnail grid. Tapping opens a
/// folder or a file through [onTap]; [menu] supplies a file's action menu.
class FilesEntries extends StatelessWidget {
const FilesEntries({
super.key,
required this.entries,
required this.view,
required this.endpoint,
required this.onTap,
required this.menu,
});
final List<DirectoryEntry> entries;
final FilesViewMode view;
final String endpoint;
final ValueChanged<DirectoryEntry> onTap;
final Widget Function(DirectoryEntry entry) menu;
@override
Widget build(BuildContext context) =>
view == FilesViewMode.grid ? _grid() : _list();
Widget _list() => ListView.builder(
itemCount: entries.length,
itemBuilder: (_, index) {
final entry = entries[index];
return ListTile(
onTap: () => onTap(entry),
leading: Icon(fileIcon(entry)),
title: Text(entry.name, maxLines: 2, overflow: TextOverflow.ellipsis),
subtitle: Text(
entry.isDir
? 'Folder'
: '${fileModifiedLabel(entry.modified)} · ${fileSizeLabel(entry.size)}',
),
trailing: entry.isDir
? null
: Row(
mainAxisSize: MainAxisSize.min,
children: [Text(fileKind(entry)), menu(entry)],
),
);
},
);
Widget _grid() => GridView.builder(
padding: const EdgeInsets.all(12),
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 180,
childAspectRatio: .85,
),
itemCount: entries.length,
itemBuilder: (_, index) {
final entry = entries[index];
return InkWell(
onTap: () => onTap(entry),
child: Card(
child: Padding(
padding: const EdgeInsets.all(12),
child: Column(
children: [
Align(
alignment: Alignment.centerRight,
child: entry.isDir ? const SizedBox(height: 48) : menu(entry),
),
Expanded(
child: Center(
child: FileThumbnail(entry: entry, endpoint: endpoint),
),
),
const SizedBox(height: 8),
Text(
entry.name,
maxLines: 2,
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.center,
),
],
),
),
),
);
},
);
}