Files
cutdex/lib/features/media/media_browser_page.dart
T
lingjhf 27e77fff39 feat: initial Cutdex application
Add the Flutter video editing application with project management, media
import, timeline editing, preview, AI assistance, diagnostics and settings.

Include shared UI and native host packages, platform runners, application
tests and release tooling.

Provide usage and contribution guides, the MIT license and third-party
notices. Exclude local credentials, build outputs and validation data.
2026-10-05 23:36:23 +08:00

169 lines
6.4 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../l10n/l10n.dart';
import '../../workspace/external_media_import.dart';
import '../../workspace/media_availability.dart';
import '../../workspace/projects.dart';
import '../../workspace/timeline_provider.dart';
import 'media_browser_body.dart';
import 'media_browser_controller.dart';
import 'media_browser_feedback.dart';
class MediaBrowserPage extends StatelessWidget {
const MediaBrowserPage({super.key, required this.projectId});
final String projectId;
@override
Widget build(BuildContext context) => TouchMediaBrowser(
key: const Key('media-browser-page'),
projectId: projectId,
);
}
class MediaBrowserDrawer extends StatelessWidget {
const MediaBrowserDrawer({super.key, required this.projectId});
final String projectId;
@override
Widget build(BuildContext context) => TouchMediaBrowser(
key: const Key('media-browser-drawer'),
projectId: projectId,
);
}
/// Touch controls share browser commands and item components with desktop.
class TouchMediaBrowser extends ConsumerWidget {
const TouchMediaBrowser({super.key, required this.projectId});
final String projectId;
@override
Widget build(BuildContext context, WidgetRef ref) {
final browser = ref.watch(mediaBrowserProvider(projectId));
ref.watch(externalMediaImportProvider(projectId));
final workspace = ref.watch(projectsProvider).value;
final timelineId = workspace?.activeProject?.id == projectId
? workspace?.timeline?.id
: null;
final timeline = timelineId == null
? null
: ref.watch(editorTimelineProvider(projectId, timelineId)).value;
return ListenableBuilder(
listenable: browser,
builder: (context, _) {
final selected = workspace?.assets
.where((asset) => asset.id == browser.selectedAssetId)
.firstOrNull;
final availability = selected == null
? null
: ref.watch(mediaAvailabilityProvider(projectId, selected)).value;
final canInsert =
browser.canEdit &&
selected != null &&
timeline?.activeSequenceId != null &&
availability == MediaAvailability.available;
return MediaImportFeedbackListener(
feedback: browser.feedback,
child: Material(
key: const Key('media-panel-surface'),
child: Column(
children: [
SizedBox(
key: const Key('media-panel-header'),
height: 56,
child: Row(
children: [
SizedBox.square(
dimension: 48,
child: IconButton(
key: const Key('media-import-button'),
tooltip: context.l10n.importMedia,
onPressed: browser.canImport
? () => pickMediaFiles(browser)
: null,
icon: const Icon(Icons.add),
),
),
Expanded(
child: DropdownButton<MediaFilter>(
key: const Key('media-category-picker'),
isExpanded: true,
underline: const SizedBox.shrink(),
value: browser.filter,
items: [
for (final filter in MediaFilter.values)
DropdownMenuItem(
value: filter,
child: Text(filter.label(context)),
),
],
onChanged: (filter) {
if (filter != null) browser.filter = filter;
},
),
),
SizedBox.square(
dimension: 48,
child: IconButton(
key: const Key('media-layout-toggle'),
tooltip: browser.grid
? context.l10n.listLayout
: context.l10n.gridLayout,
icon: Icon(
browser.grid
? Icons.view_list_outlined
: Icons.grid_view_outlined,
),
onPressed: () => browser.grid = !browser.grid,
),
),
],
),
),
if (browser.busy) const LinearProgressIndicator(),
Expanded(
key: const Key('media-panel-body'),
child: MediaBrowserBody(
projectId: projectId,
grid: browser.grid,
),
),
Padding(
padding: const EdgeInsets.all(8),
child: SizedBox(
width: double.infinity,
child: FilledButton.icon(
key: const Key('media-add-selected'),
style: FilledButton.styleFrom(
minimumSize: const Size(0, 48),
),
onPressed: !canInsert
? null
: () async {
final inserted = await browser.insertAsset(
selected,
);
if (!inserted && context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(context.l10n.operationFailed),
),
);
}
},
icon: const Icon(Icons.add),
label: Text(
context.l10n.addToTimeline,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
),
),
],
),
),
);
},
);
}
}