feat(workspace): refresh desktop editing experience and prepare 0.1.2
Gitea CI / Build Android APK (pull_request) Canceled after 0s
Gitea CI / Build Windows x64 app (pull_request) Canceled after 0s
Gitea CI / Audit and package Windows x64 (pull_request) Canceled after 0s
Gitea CI / Assemble and validate CI artifacts (pull_request) Canceled after 0s
Gitea CI / Gitea CI passed (pull_request) Canceled after 0s
Gitea CI / Check code and tests (pull_request) Canceled after 6m29s

This commit is contained in:
lingjhf committed 2026-10-09 01:56:01 +08:00
1 parent aa5255d1e4
commit 2e0033ce2d
260 files changed
+43963 -5591

No files matched your search

+2 -1
View File
@@ -8,6 +8,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../integrations/runtime/media_presentations.dart';
import 'package:cutdex_ui/icons.dart';
import 'package:cutdex_ui/theme.dart';
class AudioAssetTile extends StatelessWidget {
@@ -63,7 +64,7 @@ class _AudioWaveformCover extends ConsumerWidget {
if (waveform == null) {
return Center(
child: Icon(
Icons.audio_file_outlined,
AppIcons.audioFile,
size: AppIconSize.emptyState,
color: theme.colorScheme.onSurfaceVariant,
),
@@ -10,6 +10,7 @@ import 'package:cutdex_ui/theme.dart';
import 'package:cutdex_ui/widgets.dart';
import '../../shared/widgets/confirm_resource_download_cancel.dart';
import '../../shared/widgets/error_notification_host.dart';
import '../../shared/widgets/processing_resource_download_dialog.dart';
import '../../workspace/timeline_session.dart';
@@ -76,10 +77,10 @@ class _BackgroundRemovalDialogState
_closing = true;
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted) return;
final messenger = ScaffoldMessenger.maybeOf(context);
final notifications = ErrorNotificationHost.maybeOf(context);
final message = context.l10n.backgroundRemovalTaskStarted;
Navigator.of(context).pop();
messenger?.showSnackBar(SnackBar(content: Text(message)));
notifications?.showMessage(content: Text(message));
});
});
return ref
+143 -8
View File
@@ -1,3 +1,5 @@
import '../../shared/widgets/presentation_list.dart';
import 'package:cutdex/shared/widgets/error_notification_host.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
@@ -44,12 +46,50 @@ class BackgroundTasksContent extends ConsumerWidget {
final ProcessingResourceRepository? repository;
@override
Widget build(BuildContext context, WidgetRef ref) {
final snapshot = ref.watch(
backgroundTasksProvider(registry: registry, session: session),
final tasksProvider = backgroundTasksProvider(
registry: registry,
session: session,
);
ref.watch(
tasksProvider.select(
(snapshot) => (
PresentationList(
snapshot.subtitles.map(
(entry) => (entry.owner.session, entry.job.id),
),
),
PresentationList(
snapshot.removals.map(
(entry) => (entry.owner.session, entry.task.id),
),
),
),
),
);
final snapshot = ref.read(tasksProvider);
if (repository != null) {
ref.watch(
processingResourcesProvider(repository!).select(
(snapshot) => (
snapshot.subtitleDownloading,
PresentationList(
snapshot.installs
.where(
(install) =>
install.state == ProcessingResourceState.downloading ||
install.state == ProcessingResourceState.failed,
)
.map(
(install) => (install.package.capability, install.state),
),
),
),
),
);
}
final resources = repository == null
? null
: ref.watch(processingResourcesProvider(repository!));
: ref.read(processingResourcesProvider(repository!));
final subtitleEntries = snapshot.subtitles;
final removalEntries = snapshot.removals;
final subtitleDownloading = resources?.subtitleDownloading == true;
@@ -118,9 +158,11 @@ class BackgroundTasksContent extends ConsumerWidget {
resourceDownloads.isNotEmpty ||
subtitleDownloading)
const SizedBox(height: 2),
_BackgroundRemovalTaskCard(
key: ValueKey(entry.task.id),
_ObservedRemovalTask(
key: ValueKey((entry.owner.session, entry.task.id)),
entry: entry,
registry: registry,
session: session,
),
],
for (final (index, entry)
@@ -130,9 +172,14 @@ class BackgroundTasksContent extends ConsumerWidget {
removalEntries.isNotEmpty ||
subtitleDownloading)
const SizedBox(height: 2),
_SubtitleTaskCard(
key: ValueKey(entry.job.recognition.id),
_ObservedSubtitleTask(
key: ValueKey((
entry.owner.session,
entry.job.recognition.id,
)),
entry: entry,
registry: registry,
session: session,
),
],
],
@@ -144,6 +191,70 @@ class BackgroundTasksContent extends ConsumerWidget {
}
}
class _ObservedSubtitleTask extends ConsumerWidget {
const _ObservedSubtitleTask({
super.key,
required this.entry,
this.registry,
this.session,
});
final SubtitleTaskEntry entry;
final BackgroundTaskRegistry? registry;
final EditorTimelineSession? session;
@override
Widget build(BuildContext context, WidgetRef ref) {
final current = ref.watch(
backgroundTasksProvider(registry: registry, session: session).select(
(snapshot) => snapshot.subtitles
.where(
(item) =>
identical(item.owner.session, entry.owner.session) &&
item.job.id == entry.job.id,
)
.firstOrNull,
),
);
return current == null
? const SizedBox.shrink()
: _SubtitleTaskCard(
key: ValueKey((current.owner.session, current.job.id)),
entry: current,
);
}
}
class _ObservedRemovalTask extends ConsumerWidget {
const _ObservedRemovalTask({
super.key,
required this.entry,
this.registry,
this.session,
});
final RemovalTaskEntry entry;
final BackgroundTaskRegistry? registry;
final EditorTimelineSession? session;
@override
Widget build(BuildContext context, WidgetRef ref) {
final current = ref.watch(
backgroundTasksProvider(registry: registry, session: session).select(
(snapshot) => snapshot.removals
.where(
(item) =>
identical(item.owner.session, entry.owner.session) &&
item.task.id == entry.task.id,
)
.firstOrNull,
),
);
return current == null
? const SizedBox.shrink()
: _BackgroundRemovalTaskCard(
key: ValueKey((current.owner.session, current.task.id)),
entry: current,
);
}
}
String _ownerName(BackgroundTaskSession owner) => owner.projectName.isEmpty
? owner.timelineName
: '${owner.projectName} · ${owner.timelineName}';
@@ -387,7 +498,31 @@ class _ResourceDownloadCard extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final snapshot = ref.watch(processingResourcesProvider(repository));
final snapshot = ref.watch(
processingResourcesProvider(repository).select((snapshot) {
final capability = this.install?.package.capability;
return snapshot.copyWith(
installs: snapshot.installs
.where((install) => install.package.capability == capability)
.toList(),
paused: capability == null
? const {}
: snapshot.paused.where((item) => item == capability).toSet(),
rates: capability == null
? const {}
: {capability: snapshot.rates[capability] ?? 0},
subtitleDownloading: subtitleBundle && snapshot.subtitleDownloading,
subtitlePaused: subtitleBundle && snapshot.subtitlePaused,
subtitleDownloadedBytes: subtitleBundle
? snapshot.subtitleDownloadedBytes
: 0,
subtitleTotalBytes: subtitleBundle ? snapshot.subtitleTotalBytes : 0,
subtitleBytesPerSecond: subtitleBundle
? snapshot.subtitleBytesPerSecond
: 0,
);
}),
);
final install = this.install == null
? null
: snapshot.installs
@@ -0,0 +1,280 @@
import 'package:cutdex_sdk/project.dart';
import 'package:cutdex_ui/icons.dart';
import 'package:cutdex_ui/theme.dart';
import 'package:flutter/material.dart';
import '../../l10n/l10n.dart';
import '../../workspace/media_availability.dart';
import 'audio_asset_tile.dart';
import 'media_asset_strip.dart';
import 'media_browser_layout.dart';
import 'unavailable_media_placeholder.dart';
import 'visual_asset_tile.dart';
/// Desktop cards and rows use the same cover, name and availability labels.
class DesktopMediaAssetTile extends StatelessWidget {
const DesktopMediaAssetTile({
super.key,
required this.asset,
required this.grid,
required this.availability,
});
final AssetDocument asset;
final bool grid;
final MediaAvailability? availability;
static TextStyle? _nameStyle(BuildContext context) =>
Theme.of(context).textTheme.bodyMedium
?.copyWith(fontSize: 13, height: 20 / 13);
static TextStyle? _metadataStyle(BuildContext context) =>
Theme.of(context).textTheme.bodySmall
?.copyWith(fontSize: 12, height: 16 / 12);
/// Font fallback and fractional scaling can round a line above size × height.
static double gridLabelHeight(BuildContext context) {
double lineHeight(TextStyle? style) {
final painter = TextPainter(
text: TextSpan(text: '国Ag', style: style),
maxLines: 1,
textDirection: Directionality.of(context),
textScaler: MediaQuery.textScalerOf(context),
locale: Localizations.maybeLocaleOf(context),
textHeightBehavior: DefaultTextStyle.of(context).textHeightBehavior,
)..layout();
final height = painter.height.ceilToDouble();
painter.dispose();
return height;
}
return lineHeight(_nameStyle(context)) +
lineHeight(_metadataStyle(context));
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final unavailable =
availability != null && availability != MediaAvailability.available;
final kind = switch (asset.metadata['kind']) {
'video' => context.l10n.video,
'image' => context.l10n.picture,
'audio' => context.l10n.audio,
_ => context.l10n.materials,
};
final width = asset.metadata['width'];
final height = asset.metadata['height'];
final dimensions = width is num && height is num && width > 0 && height > 0
? '${width.toInt()} × ${height.toInt()}'
: null;
final info = unavailable
? availability == MediaAvailability.missing
? context.l10n.mediaMissing
: context.l10n.mediaUnavailable
: dimensions == null
? kind
: '$kind · $dimensions';
final name = Tooltip(
message: asset.name,
child: Text(
asset.name,
key: ValueKey('media-name-${asset.id}'),
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: _nameStyle(context),
),
);
Widget metadata({bool showDuration = false}) => Row(
children: [
Flexible(
child: Text(
info,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: _metadataStyle(context)?.copyWith(
color: unavailable
? theme.colorScheme.error
: theme.colorScheme.onSurfaceVariant,
),
),
),
if (showDuration && !unavailable) ...[
const SizedBox(width: 8),
Flexible(child: MediaAssetDuration(asset: asset, badge: false)),
],
],
);
final cover = ClipRRect(
key: ValueKey('desktop-media-cover-${asset.id}'),
borderRadius: BorderRadius.circular(4),
child: Stack(
children: [
if (unavailable)
AspectRatio(
aspectRatio: 16 / 9,
child: UnavailableMediaPlaceholder(
availability: availability!,
showLabel: false,
),
)
else
switch (asset.metadata['kind']) {
'video' ||
'image' => VisualAssetTile(asset: asset, showName: false),
'audio' => AudioAssetTile(asset: asset, showName: false),
_ => AspectRatio(
aspectRatio: 16 / 9,
child: ColoredBox(
color: AppSurfaces.of(context).previewBackground,
child: const Center(child: Icon(AppIcons.file, size: 20)),
),
),
},
if (grid && !unavailable)
Positioned(
bottom: 4,
left: 4,
right: 4,
child: Align(
alignment: AlignmentDirectional.centerEnd,
child: MediaAssetDuration(asset: asset),
),
),
],
),
);
if (!grid) {
return LayoutBuilder(
builder: (context, constraints) {
final columns = DesktopMediaListColumns(constraints.maxWidth);
return Row(
children: [
SizedBox(
width: DesktopMediaMetrics.listCover,
height: DesktopMediaMetrics.listCover * 9 / 16,
child: cover,
),
const SizedBox(width: DesktopMediaMetrics.gap),
Expanded(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
name,
if (!columns.specification)
metadata(showDuration: !columns.duration),
],
),
),
if (columns.duration)
SizedBox(
width: DesktopMediaListColumns.durationWidth,
child: Align(
alignment: AlignmentDirectional.centerEnd,
child: unavailable
? const SizedBox.shrink()
: MediaAssetDuration(asset: asset, badge: false),
),
),
if (columns.specification) ...[
const SizedBox(width: DesktopMediaMetrics.gap),
SizedBox(
width: DesktopMediaListColumns.specificationWidth,
child: Text(
unavailable ? info : dimensions ?? '—',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: _metadataStyle(context)?.copyWith(
color: unavailable
? theme.colorScheme.error
: theme.colorScheme.onSurfaceVariant,
),
),
),
],
if (columns.kind) ...[
const SizedBox(width: DesktopMediaMetrics.gap),
SizedBox(
width: DesktopMediaListColumns.kindWidth,
child: Text(
kind,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: _metadataStyle(context),
),
),
],
],
);
},
);
}
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [cover, const SizedBox(height: 4), name, metadata()],
);
}
}
/// List labels follow the same column widths and breakpoints as asset rows.
class DesktopMediaListHeader extends StatelessWidget {
const DesktopMediaListHeader({super.key});
@override
Widget build(BuildContext context) => Padding(
padding: const EdgeInsets.symmetric(
horizontal: DesktopMediaMetrics.padding + DesktopMediaMetrics.tilePadding,
),
child: LayoutBuilder(
builder: (context, constraints) {
final columns = DesktopMediaListColumns(constraints.maxWidth);
Widget label(String text, {bool end = false}) => Text(
text,
maxLines: 1,
overflow: TextOverflow.ellipsis,
textAlign: end ? TextAlign.end : TextAlign.start,
style: DesktopMediaAssetTile._metadataStyle(context)
?.copyWith(color: Theme.of(context).colorScheme.onSurfaceVariant),
);
return SizedBox(
height: (MediaQuery.textScalerOf(context).scale(16) + 8).clamp(
DesktopMediaMetrics.listHeader,
double.infinity,
),
child: Row(
children: [
Expanded(
child: Padding(
padding: const EdgeInsetsDirectional.only(
start:
DesktopMediaMetrics.listCover + DesktopMediaMetrics.gap,
),
child: label(context.l10n.name),
),
),
if (columns.duration)
SizedBox(
width: DesktopMediaListColumns.durationWidth,
child: label(context.l10n.duration, end: true),
),
if (columns.specification) ...[
const SizedBox(width: DesktopMediaMetrics.gap),
SizedBox(
width: DesktopMediaListColumns.specificationWidth,
child: label(context.l10n.mediaSpecification),
),
],
if (columns.kind) ...[
const SizedBox(width: DesktopMediaMetrics.gap),
SizedBox(
width: DesktopMediaListColumns.kindWidth,
child: label(context.l10n.mediaCategory),
),
],
],
),
);
},
),
);
}
+21 -3
View File
@@ -6,6 +6,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../integrations/runtime/media_presentations.dart';
import 'package:cutdex_ui/icons.dart';
import 'package:cutdex_ui/theme.dart';
import 'audio_asset_tile.dart';
@@ -64,9 +65,9 @@ class _VisualAssetStrip extends ConsumerWidget {
timeMilliseconds: video && duration != null
? (duration * 1000 * index / count).floor()
: 0,
fallback: const Center(child: Icon(Icons.movie_outlined)),
fallback: const Center(child: Icon(AppIcons.video)),
errorFallback: const Center(
child: Icon(Icons.broken_image_outlined),
child: Icon(AppIcons.imageUnavailable),
),
),
),
@@ -77,8 +78,9 @@ class _VisualAssetStrip extends ConsumerWidget {
}
class MediaAssetDuration extends ConsumerWidget {
const MediaAssetDuration({super.key, required this.asset});
const MediaAssetDuration({super.key, required this.asset, this.badge = true});
final AssetDocument asset;
final bool badge;
@override
Widget build(BuildContext context, WidgetRef ref) {
@@ -94,6 +96,20 @@ class MediaAssetDuration extends ConsumerWidget {
'${hours > 0 ? '$hours:' : ''}'
'${minutes.toString().padLeft(2, '0')}:'
'${(seconds % 60).toString().padLeft(2, '0')}';
if (!badge) {
return Text(
text,
key: ValueKey('media-duration-${asset.id}'),
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.bodySmall?.copyWith(
fontSize: 12,
height: 16 / 12,
color: Theme.of(context).colorScheme.onSurfaceVariant,
fontFeatures: const [FontFeature.tabularFigures()],
),
);
}
return DecoratedBox(
decoration: BoxDecoration(
color: Colors.black.withValues(alpha: .55),
@@ -104,6 +120,8 @@ class MediaAssetDuration extends ConsumerWidget {
child: Text(
text,
key: ValueKey('media-duration-${asset.id}'),
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Colors.white,
fontFeatures: const [FontFeature.tabularFigures()],
+440 -151
View File
@@ -1,3 +1,5 @@
import '../../shared/widgets/listenable_selector.dart';
import 'package:cutdex/shared/widgets/error_notification_host.dart';
import 'package:cutdex/errors/app_failure.dart';
@@ -11,19 +13,24 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../integrations/platform/platform_capabilities.dart';
import 'package:cutdex_ui/icons.dart';
import 'package:cutdex_ui/theme.dart';
import 'package:cutdex_ui/widgets.dart';
import '../../workspace/external_media_import.dart';
import '../../workspace/media_availability.dart';
import '../../workspace/project_state.dart';
import '../../workspace/projects.dart';
import '../../workspace/timeline_provider.dart';
import '../../workspace/timeline_session.dart';
import 'audio_asset_tile.dart';
import 'media_asset_drag.dart';
import 'media_asset_strip.dart';
import 'media_browser_controller.dart';
import 'unavailable_media_placeholder.dart';
import 'visual_asset_tile.dart';
import 'desktop_media_asset_tile.dart';
import 'media_browser_layout.dart';
extension MediaFilterLabel on MediaFilter {
String label(BuildContext context) => switch (this) {
@@ -44,26 +51,37 @@ class MediaBrowserBody extends ConsumerStatefulWidget {
required this.grid,
this.draggable = false,
this.compact = false,
this.desktop = false,
});
final String projectId;
final bool grid;
final bool draggable;
final bool compact;
final bool desktop;
@override
ConsumerState<MediaBrowserBody> createState() => _MediaBrowserBodyState();
}
class _MediaBrowserBodyState extends ConsumerState<MediaBrowserBody>
with WidgetsBindingObserver {
final _desktopScroll = _MediaScrollController();
MediaBrowserController? _anchorOwner;
List<AssetDocument> _anchorAssets = const [];
int _anchorColumns = 1;
double _anchorStride = 1;
Object? _viewportConfiguration;
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
_desktopScroll.addListener(_storeBrowseAnchor);
}
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
_desktopScroll.dispose();
super.dispose();
}
@@ -83,6 +101,67 @@ class _MediaBrowserBodyState extends ConsumerState<MediaBrowserBody>
bool get _isGrid => widget.grid;
bool get _desktop => ref.read(platformCapabilitiesProvider).nativeFileDrop;
void _storeBrowseAnchor() {
if (_anchorOwner == null ||
_anchorAssets.isEmpty ||
!_desktopScroll.hasClients) {
return;
}
final rowPosition = math.max(
0.0,
(_desktopScroll.position.pixels - DesktopMediaMetrics.padding) /
_anchorStride,
);
final row = rowPosition.floor();
final index = math.min(_anchorAssets.length - 1, row * _anchorColumns);
_anchorOwner!.viewportAnchor = (
assetId: _anchorAssets[index].id,
fraction: rowPosition - row,
);
}
void _prepareDesktopScroll({
required List<AssetDocument> assets,
required Object configuration,
required int columns,
required double extent,
required double height,
}) {
if (_viewportConfiguration == configuration) return;
_viewportConfiguration = configuration;
final owner = _browser;
final anchor = owner.viewportAnchor;
final index = anchor == null
? -1
: assets.indexWhere((asset) => asset.id == anchor.assetId);
final stride = extent + DesktopMediaMetrics.gap;
final row = index < 0 ? 0 : index ~/ columns;
final fraction = index < 0 ? 0.0 : anchor!.fraction;
final rows = (assets.length / columns).ceil();
final maximum = math.max(
0.0,
DesktopMediaMetrics.padding * 2 +
rows * stride -
(_isGrid && rows > 0 ? DesktopMediaMetrics.gap : 0) -
height,
);
final offset =
(row == 0 && fraction == 0
? 0.0
: DesktopMediaMetrics.padding + (row + fraction) * stride)
.clamp(0.0, maximum);
_anchorOwner = owner;
_anchorAssets = assets;
_anchorColumns = columns;
_anchorStride = stride;
_desktopScroll.initialOffset = offset;
// Layout consumes the corrected pixels before painting. No change
// notification or post-frame jump is needed to preserve the browse anchor.
for (final position in _desktopScroll.positions) {
if (position.pixels != offset) position.correctPixels(offset);
}
}
Future<void> _action(Future<bool> Function() action) async {
final ok = await action();
if (!mounted || ok) return;
@@ -116,12 +195,19 @@ class _MediaBrowserBodyState extends ConsumerState<MediaBrowserBody>
],
child: AppField(
label: context.l10n.name,
child: TextField(
controller: controller,
autofocus: true,
onSubmitted: (value) {
if (value.trim().isNotEmpty) Navigator.pop(context, value.trim());
},
child: Builder(
builder: (fieldContext) => TextField(
controller: controller,
autofocus: true,
style: AppTheme.inputTextStyle(fieldContext),
cursorHeight: AppTheme.inputCursorHeight(fieldContext),
textAlignVertical: TextAlignVertical.center,
onSubmitted: (value) {
if (value.trim().isNotEmpty) {
Navigator.pop(context, value.trim());
}
},
),
),
),
),
@@ -159,12 +245,14 @@ class _MediaBrowserBodyState extends ConsumerState<MediaBrowserBody>
}
@override
Widget build(BuildContext context) => ListenableBuilder(
listenable: ref.watch(mediaBrowserProvider(widget.projectId)),
builder: (context, _) => _buildBrowser(context),
);
Widget _buildBrowser(BuildContext context) {
ref.watch(externalMediaImportProvider(widget.projectId));
Widget build(BuildContext context) {
final browser = ref.watch(mediaBrowserProvider(widget.projectId));
// Provider subscriptions belong to this Consumer's build lifecycle. Local
// selector rebuilds must not register watches on this outer ref.
ref.watch(
externalMediaImportProvider(widget.projectId)
.select((value) => value.isLoading),
);
ref.watch(
projectsProvider.select(
(value) => (
@@ -177,12 +265,6 @@ class _MediaBrowserBodyState extends ConsumerState<MediaBrowserBody>
);
final workspace = ref.read(projectsProvider).value;
final active = workspace?.activeProject?.id == widget.projectId;
final allAssets = active ? workspace!.assets : <AssetDocument>[];
final assets = _filter == MediaFilter.all
? allAssets
: allAssets
.where((asset) => asset.metadata['kind'] == _filter.kind)
.toList();
final timelineId = active ? workspace?.timeline?.id : null;
final timeline = timelineId == null
? null
@@ -190,12 +272,40 @@ class _MediaBrowserBodyState extends ConsumerState<MediaBrowserBody>
.watch(editorTimelineProvider(widget.projectId, timelineId))
.asData
?.value;
return assets.isEmpty
return ListenableSelector(
listenable: browser,
select: () => (
browser.filter,
widget.desktop ? browser.query : '',
widget.desktop ? browser.sort : MediaSort.importOrder,
widget.desktop ? browser.gridSize : MediaGridSize.medium,
),
builder: (context, _) => _buildBrowser(context, workspace, timeline),
);
}
Widget _buildBrowser(
BuildContext context,
ProjectState? workspace,
EditorTimelineSession? timeline,
) {
final active = workspace?.activeProject?.id == widget.projectId;
final timelineId = active ? workspace?.timeline?.id : null;
final allAssets = active ? workspace!.assets : <AssetDocument>[];
final assets = _browser.visibleAssets(allAssets, desktop: widget.desktop);
if (widget.desktop && assets.isEmpty) {
_viewportConfiguration = null;
_anchorOwner = null;
_anchorAssets = const [];
}
final content = assets.isEmpty
? Center(
child: Padding(
padding: const EdgeInsets.all(AppSpacing.medium),
child: Text(
_filter != MediaFilter.all
widget.desktop && _browser.query.trim().isNotEmpty
? context.l10n.noMatchingMedia
: _filter != MediaFilter.all
? context.l10n.noMediaOfType(_filter.label(context))
: _desktop
? context.l10n.dragMediaHint
@@ -206,16 +316,25 @@ class _MediaBrowserBodyState extends ConsumerState<MediaBrowserBody>
)
: LayoutBuilder(
builder: (context, constraints) {
final spacing = widget.compact
final spacing = widget.desktop
? DesktopMediaMetrics.gap
: widget.compact
? AppSpacing.gap
: AppSpacing.small;
final padding = widget.compact
final padding = widget.desktop
? DesktopMediaMetrics.padding
: widget.compact
? AppSidebarMetrics.outerPadding
: AppSpacing.compact;
final width = math.max(1.0, constraints.maxWidth - padding * 2);
final columns = math.max(
1,
widget.compact
widget.desktop
? DesktopMediaMetrics.columns(
width,
_browser.gridSize.targetWidth,
)
: widget.compact
? ((width + spacing) /
(maximumCompactMediaGridTileWidth + spacing))
.ceil()
@@ -228,6 +347,41 @@ class _MediaBrowserBodyState extends ConsumerState<MediaBrowserBody>
final labelHeight =
MediaQuery.textScalerOf(context).scale(textStyle.fontSize!) *
(textStyle.height ?? 1.2);
final desktopLabelHeight = widget.desktop && _isGrid
? DesktopMediaAssetTile.gridLabelHeight(context)
: 0.0;
final desktopExtent = !widget.desktop
? 0.0
: _isGrid
? DesktopMediaMetrics.gridExtent(
tileWidth,
desktopLabelHeight,
)
: math.max(
DesktopMediaMetrics.listRow,
DesktopMediaAssetTile.gridLabelHeight(context) +
DesktopMediaMetrics.tilePadding * 2,
);
if (widget.desktop) {
_prepareDesktopScroll(
assets: assets,
configuration: (
widget.projectId,
_browser,
_isGrid,
columns,
desktopExtent,
constraints.maxHeight,
_filter,
_browser.query,
_browser.sort,
allAssets,
),
columns: _isGrid ? columns : 1,
extent: desktopExtent,
height: constraints.maxHeight,
);
}
Widget item(BuildContext context, int index) {
final asset = assets[index];
return Consumer(
@@ -241,76 +395,85 @@ class _MediaBrowserBodyState extends ConsumerState<MediaBrowserBody>
final unavailable =
availability != null &&
availability != MediaAvailability.available;
return AppContextMenu(
key: ValueKey(('media-menu', asset.id)),
itemsBuilder: (_) {
final available = ref
.read(projectsProvider)
.asData
?.value;
final canEdit =
available?.activeProject?.id == widget.projectId &&
available?.projectBusy == false &&
!_checkingDrop;
final sequence = timeline?.activeSequenceId;
return [
AppMenuItem(
label: context.l10n.addToTimeline,
icon: Icons.add,
onPressed:
canEdit &&
!unavailable &&
sequence != null &&
available?.timeline?.id == timelineId
? () =>
_action(() => _browser.insertAsset(asset))
: null,
),
AppMenuItem(
label: context.l10n.rename,
icon: Icons.drive_file_rename_outline,
onPressed: canEdit ? () => _rename(asset) : null,
),
AppMenuItem(
label: defaultTargetPlatform == TargetPlatform.macOS
? context.l10n.revealFinder
: context.l10n.revealFileManager,
icon: Icons.folder_open,
onPressed: canEdit && _desktop
? () => _action(() => _browser.reveal(asset))
: null,
),
const AppMenuSeparator(),
AppMenuItem(
label: context.l10n.removeMedia,
icon: Icons.delete_outline,
destructive: true,
onPressed: canEdit ? () => _remove(asset) : null,
),
];
},
child: Listener(
onPointerDown: (event) {
if (event.buttons == 2) {
setState(() => _selectedAssetId = asset.id);
}
return ListenableSelector<(bool, bool)>(
listenable: _browser,
select: () =>
(_selectedAssetId == asset.id, _checkingDrop),
builder: (context, presentation) => AppContextMenu(
key: ValueKey(('media-menu', asset.id)),
itemsBuilder: (_) {
final available = ref
.read(projectsProvider)
.asData
?.value;
final canEdit =
available?.activeProject?.id ==
widget.projectId &&
available?.projectBusy == false &&
!_checkingDrop;
final sequence = timeline?.activeSequenceId;
return [
AppMenuItem(
label: context.l10n.addToTimeline,
icon: AppIcons.add,
onPressed:
canEdit &&
!unavailable &&
sequence != null &&
available?.timeline?.id == timelineId
? () => _action(
() => _browser.insertAsset(asset),
)
: null,
),
AppMenuItem(
label: context.l10n.rename,
icon: AppIcons.rename,
onPressed: canEdit ? () => _rename(asset) : null,
),
AppMenuItem(
label:
defaultTargetPlatform == TargetPlatform.macOS
? context.l10n.revealFinder
: context.l10n.revealFileManager,
icon: AppIcons.folderOpen,
onPressed: canEdit && _desktop
? () => _action(() => _browser.reveal(asset))
: null,
),
const AppMenuSeparator(),
AppMenuItem(
label: context.l10n.removeMedia,
icon: AppIcons.delete,
destructive: true,
onPressed: canEdit ? () => _remove(asset) : null,
),
];
},
child: _SelectableAsset(
key: ValueKey(asset.id),
grid: _isGrid,
drag: MediaAssetDrag(
projectId: widget.projectId,
assetId: asset.id,
child: Listener(
onPointerDown: (event) {
if (event.buttons == 2) {
_selectedAssetId = asset.id;
}
},
child: _SelectableAsset(
key: ValueKey(asset.id),
grid: _isGrid,
desktop: widget.desktop,
drag: MediaAssetDrag(
projectId: widget.projectId,
assetId: asset.id,
),
name: asset.name,
draggable:
widget.draggable &&
!workspace!.projectBusy &&
!presentation.$2 &&
!unavailable,
selected: presentation.$1,
onTap: () => _browser.selectAsset(asset),
child: _assetTile(asset, availability),
),
name: asset.name,
draggable:
widget.draggable &&
!workspace!.projectBusy &&
!_checkingDrop &&
!unavailable,
selected: _selectedAssetId == asset.id,
onTap: () => _browser.selectAsset(asset),
child: _assetTile(asset, availability),
),
),
);
@@ -318,44 +481,122 @@ class _MediaBrowserBodyState extends ConsumerState<MediaBrowserBody>
);
}
Widget scrollView(ScrollController controller) => !_isGrid
? widget.desktop
? ListView.builder(
key: PageStorageKey((
'media-list',
widget.projectId,
)),
controller: controller,
padding: EdgeInsets.all(padding),
itemCount: assets.length,
itemExtent: desktopExtent + spacing,
itemBuilder: (context, index) => Padding(
padding: EdgeInsets.only(bottom: spacing),
child: item(context, index),
),
)
: ListView.separated(
key: PageStorageKey((
'media-list',
widget.projectId,
)),
controller: controller,
padding: EdgeInsets.all(padding),
itemCount: assets.length,
itemBuilder: item,
separatorBuilder: (_, _) =>
SizedBox(height: spacing),
)
: GridView.builder(
key: PageStorageKey(('media-grid', widget.projectId)),
controller: controller,
padding: EdgeInsets.all(padding),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: columns,
crossAxisSpacing: spacing,
mainAxisSpacing: widget.desktop || widget.compact
? spacing
: AppSpacing.compact,
mainAxisExtent: widget.desktop
? desktopExtent
: tileWidth * 9 / 16 +
(widget.compact
? AppSpacing.gap
: AppSpacing.small) +
labelHeight +
2,
),
itemCount: assets.length,
itemBuilder: item,
);
if (widget.desktop) {
return ScrollEdgeFade(
controller: _desktopScroll,
child: scrollView(_desktopScroll),
);
}
return ScrollEdgeFadeBuilder(
key: ValueKey(('media-scroll-fade', widget.projectId, _isGrid)),
builder: (controller) => !_isGrid
? ListView.separated(
key: PageStorageKey(('media-list', widget.projectId)),
controller: controller,
padding: EdgeInsets.all(padding),
itemCount: assets.length,
itemBuilder: item,
separatorBuilder: (_, _) => SizedBox(height: spacing),
)
: GridView.builder(
key: PageStorageKey(('media-grid', widget.projectId)),
controller: controller,
padding: EdgeInsets.all(padding),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: columns,
crossAxisSpacing: spacing,
mainAxisSpacing: widget.compact
? spacing
: AppSpacing.compact,
mainAxisExtent:
tileWidth * 9 / 16 +
(widget.compact
? AppSpacing.gap
: AppSpacing.small) +
labelHeight +
2,
),
itemCount: assets.length,
itemBuilder: item,
),
builder: scrollView,
);
},
);
if (!widget.desktop) return content;
return Column(
children: [
if (!_isGrid)
const DesktopMediaListHeader(key: Key('media-list-header')),
Expanded(child: content),
const Divider(height: 1),
SizedBox(
key: const Key('media-browser-footer'),
height: 28,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 12),
child: ListenableSelector(
listenable: _browser,
select: () => assets.any((asset) => asset.id == _selectedAssetId),
builder: (context, selected) => Row(
children: [
Expanded(
child: Text(
context.l10n.mediaCount(assets.length),
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.bodySmall,
),
),
if (selected)
Flexible(
child: Align(
alignment: AlignmentDirectional.centerEnd,
child: Text(
context.l10n.mediaSelectedCount(1),
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.bodySmall,
),
),
),
],
),
),
),
),
],
);
}
Widget _assetTile(AssetDocument asset, MediaAvailability? availability) {
if (widget.desktop) {
return DesktopMediaAssetTile(
asset: asset,
grid: _isGrid,
availability: availability,
);
}
final unavailable =
availability != null && availability != MediaAvailability.available;
final cover = unavailable
@@ -388,7 +629,7 @@ class _MediaBrowserBodyState extends ConsumerState<MediaBrowserBody>
aspectRatio: 16 / 9,
child: ColoredBox(
color: AppSurfaces.of(context).previewBackground,
child: const Icon(Icons.insert_drive_file_outlined),
child: const Icon(AppIcons.file),
),
),
};
@@ -429,10 +670,28 @@ class _MediaBrowserBodyState extends ConsumerState<MediaBrowserBody>
}
}
class _MediaScrollController extends ScrollController {
_MediaScrollController() : super(keepScrollOffset: false);
double initialOffset = 0;
@override
ScrollPosition createScrollPosition(
ScrollPhysics physics,
ScrollContext context,
ScrollPosition? oldPosition,
) => ScrollPositionWithSingleContext(
physics: physics,
context: context,
initialPixels: initialOffset,
keepScrollOffset: false,
);
}
class _SelectableAsset extends StatelessWidget {
const _SelectableAsset({
super.key,
required this.grid,
this.desktop = false,
required this.selected,
required this.drag,
required this.name,
@@ -443,6 +702,7 @@ class _SelectableAsset extends StatelessWidget {
final bool selected;
final bool grid;
final bool desktop;
final MediaAssetDrag drag;
final String name;
final bool draggable;
@@ -457,39 +717,68 @@ class _SelectableAsset extends StatelessWidget {
);
final tile = Semantics(
selected: selected,
child: InkWell(
onTap: onTap,
hoverColor: Colors.transparent,
highlightColor: Colors.transparent,
splashFactory: NoSplash.splashFactory,
child: Stack(
children: [
child,
if (selected && !grid)
Positioned(
top: 0,
left: 0,
right: 0,
height: MediaAssetStrip.height,
child: IgnorePointer(
child: DecoratedBox(decoration: selectionDecoration),
child: desktop
? Material(
color: selected
? Theme.of(context).colorScheme.primary.withValues(alpha: .08)
: Colors.transparent,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(6),
side: BorderSide(
color: selected
? Theme.of(context).colorScheme.primary
: Colors.transparent,
),
),
if (selected && grid)
Positioned(
top: 0,
left: 0,
right: 0,
child: IgnorePointer(
child: AspectRatio(
aspectRatio: 16 / 9,
child: DecoratedBox(decoration: selectionDecoration),
),
clipBehavior: Clip.antiAlias,
child: InkWell(
onTap: onTap,
hoverColor: Theme.of(context).colorScheme.onSurface
.withValues(alpha: .05),
child: Padding(
padding: const EdgeInsets.all(5),
child: grid
? child
: ConstrainedBox(
constraints: const BoxConstraints(minHeight: 38),
child: child,
),
),
),
],
),
),
)
: InkWell(
onTap: onTap,
hoverColor: Colors.transparent,
highlightColor: Colors.transparent,
splashFactory: NoSplash.splashFactory,
child: Stack(
children: [
child,
if (selected && !grid)
Positioned(
top: 0,
left: 0,
right: 0,
height: MediaAssetStrip.height,
child: IgnorePointer(
child: DecoratedBox(decoration: selectionDecoration),
),
),
if (selected && grid)
Positioned(
top: 0,
left: 0,
right: 0,
child: IgnorePointer(
child: AspectRatio(
aspectRatio: 16 / 9,
child: DecoratedBox(decoration: selectionDecoration),
),
),
),
],
),
),
);
return Draggable<MediaAssetDrag>(
data: drag,
@@ -14,6 +14,8 @@ import '../../workspace/timeline_provider.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'resource_section.dart';
enum MediaFilter {
all(null),
image('image'),
@@ -24,6 +26,18 @@ enum MediaFilter {
final String? kind;
}
enum MediaSort { importOrder, nameAscending, nameDescending }
/// Desktop thumbnail density, independent of touch-page presentation.
enum MediaGridSize {
small(120),
medium(160),
large(200);
const MediaGridSize(this.targetWidth);
final double targetWidth;
}
final mediaBrowserProvider = Provider.family<MediaBrowserController, String>((
ref,
projectId,
@@ -41,8 +55,9 @@ class MediaBrowserController extends ChangeNotifier {
final feedback = MediaImportFeedbackController();
bool _working = false;
bool _disposed = false;
bool get busy =>
_working || _ref.read(externalMediaImportProvider(projectId)).isLoading;
bool get importing =>
_ref.read(externalMediaImportProvider(projectId)).isLoading;
bool get busy => _working || importing;
bool get active =>
!_disposed &&
_ref.mounted &&
@@ -81,7 +96,11 @@ class MediaBrowserController extends ChangeNotifier {
.importFiles(files);
final asset = result?.selected.firstOrNull;
if (!_disposed && asset != null) {
_resourceSection = ResourceSection.imported;
_selectedAssetId = asset.id;
if (!asset.name.toLowerCase().contains(_query.trim().toLowerCase())) {
_query = '';
}
if (_filter != MediaFilter.all &&
asset.metadata['kind'] != _filter.kind) {
_filter = MediaFilter.all;
@@ -172,23 +191,87 @@ class MediaBrowserController extends ChangeNotifier {
String? _selectedAssetId;
MediaFilter _filter = MediaFilter.all;
bool _grid = true;
String _query = '';
MediaSort _sort = MediaSort.importOrder;
MediaGridSize _gridSize = MediaGridSize.medium;
ResourceSection _resourceSection = ResourceSection.imported;
/// The first visible desktop asset and its fraction through the current row.
/// Scroll updates are silent; browsing does not rebuild controls or metadata.
({String assetId, double fraction})? viewportAnchor;
String? get selectedAssetId => _selectedAssetId;
MediaFilter get filter => _filter;
bool get grid => _grid;
String get query => _query;
MediaSort get sort => _sort;
MediaGridSize get gridSize => _gridSize;
ResourceSection get resourceSection => _resourceSection;
/// Resource libraries are desktop navigation, separate from media filters.
set resourceSection(ResourceSection value) {
if (_resourceSection == value) return;
_resourceSection = value;
notifyListeners();
}
/// Touch pages keep their own presentation while sharing category selection.
List<AssetDocument> visibleAssets(
Iterable<AssetDocument> assets, {
bool desktop = false,
}) {
final query = desktop ? _query.trim().toLowerCase() : '';
final result = assets
.where(
(asset) =>
(_filter == MediaFilter.all ||
asset.metadata['kind'] == _filter.kind) &&
asset.name.toLowerCase().contains(query),
)
.toList();
if (desktop && _sort != MediaSort.importOrder) {
result.sort((a, b) {
var order = a.name.toLowerCase().compareTo(b.name.toLowerCase());
if (order == 0) order = a.id.compareTo(b.id);
return _sort == MediaSort.nameDescending ? -order : order;
});
}
return result;
}
set query(String value) {
if (_query == value) return;
_query = value;
notifyListeners();
}
set sort(MediaSort value) {
if (_sort == value) return;
_sort = value;
notifyListeners();
}
set selectedAssetId(String? value) {
if (_selectedAssetId == value) return;
_selectedAssetId = value;
notifyListeners();
}
set filter(MediaFilter value) {
if (_filter == value) return;
_filter = value;
notifyListeners();
}
set grid(bool value) {
if (_grid == value) return;
_grid = value;
notifyListeners();
}
set gridSize(MediaGridSize value) {
if (_gridSize == value) return;
_gridSize = value;
notifyListeners();
}
}
@@ -0,0 +1,33 @@
import 'dart:math' as math;
/// Shared desktop geometry for cards, rows, headers and browse anchoring.
abstract final class DesktopMediaMetrics {
static const padding = 12.0;
static const gap = 8.0;
static const tilePadding = 5.0;
static const listCover = 56.0;
static const listRow = 48.0;
static const listHeader = 28.0;
static int columns(double width, double targetWidth) =>
math.max(1, ((width + gap) / (targetWidth + gap)).floor());
static double gridExtent(double tileWidth, double labelHeight) =>
(tileWidth - tilePadding * 2) * 9 / 16 +
4 +
labelHeight +
tilePadding * 2;
}
/// Matching list-column visibility for a header and its asset rows.
final class DesktopMediaListColumns {
const DesktopMediaListColumns(double width)
: duration = width >= 240,
specification = width >= 480,
kind = width >= 620;
final bool duration, specification, kind;
static const durationWidth = 64.0;
static const specificationWidth = 136.0;
static const kindWidth = 56.0;
}
+23 -11
View File
@@ -1,4 +1,5 @@
import 'package:cutdex/shared/widgets/error_notification_host.dart';
import 'package:cutdex_ui/icons.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
@@ -39,8 +40,19 @@ class TouchMediaBrowser extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final browser = ref.watch(mediaBrowserProvider(projectId));
ref.watch(externalMediaImportProvider(projectId));
final workspace = ref.watch(projectsProvider).value;
ref.watch(
externalMediaImportProvider(projectId).select((value) => value.isLoading),
);
final workspace = ref.watch(
projectsProvider.select(
(value) => value.value?.copyWith(
recent: const [],
timelines: const [],
error: null,
creatingTimeline: false,
),
),
);
final timelineId = workspace?.activeProject?.id == projectId
? workspace?.timeline?.id
: null;
@@ -72,20 +84,20 @@ class TouchMediaBrowser extends ConsumerWidget {
height: 56,
child: Row(
children: [
SizedBox.square(
dimension: 48,
child: IconButton(
SizedBox(
height: 48,
child: TextButton(
key: const Key('media-import-button'),
tooltip: context.l10n.importMedia,
onPressed: browser.canImport
? () => pickMediaFiles(browser)
: null,
icon: const Icon(Icons.add),
child: Text(context.l10n.importMedia),
),
),
Expanded(
child: DropdownButton<MediaFilter>(
key: const Key('media-category-picker'),
icon: const Icon(AppIcons.expandMore),
isExpanded: true,
underline: const SizedBox.shrink(),
value: browser.filter,
@@ -110,8 +122,8 @@ class TouchMediaBrowser extends ConsumerWidget {
: context.l10n.gridLayout,
icon: Icon(
browser.grid
? Icons.view_list_outlined
: Icons.grid_view_outlined,
? AppIcons.listView
: AppIcons.gridView,
),
onPressed: () => browser.grid = !browser.grid,
),
@@ -119,7 +131,7 @@ class TouchMediaBrowser extends ConsumerWidget {
],
),
),
if (browser.busy) const LinearProgressIndicator(),
if (browser.importing) const LinearProgressIndicator(),
Expanded(
key: const Key('media-panel-body'),
child: MediaBrowserBody(
@@ -150,7 +162,7 @@ class TouchMediaBrowser extends ConsumerWidget {
);
}
},
icon: const Icon(Icons.add),
icon: const Icon(AppIcons.add),
label: Text(
context.l10n.addToTimeline,
maxLines: 1,
+438 -76
View File
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:cutdex_ui/icons.dart';
import 'package:cutdex_ui/theme.dart';
import 'package:cutdex_ui/widgets.dart';
@@ -6,6 +7,7 @@ import '../../l10n/l10n.dart';
import '../../workspace/project_state.dart';
import 'media_browser_body.dart';
import 'media_browser_controller.dart';
import 'resource_navigation.dart';
class MediaBrowserToolbar extends StatefulWidget {
const MediaBrowserToolbar({
@@ -19,6 +21,16 @@ class MediaBrowserToolbar extends StatefulWidget {
this.projects = const [],
this.selectedProjectId,
this.onProjectSelected,
this.desktop = false,
this.query = '',
this.onQueryChanged,
this.sort = MediaSort.importOrder,
this.onSortChanged,
this.projectScoped = false,
this.resourceSection = ResourceSection.imported,
this.onResourceSectionChanged,
this.gridSize = MediaGridSize.medium,
this.onGridSizeChanged,
});
final bool canImport;
@@ -30,6 +42,16 @@ class MediaBrowserToolbar extends StatefulWidget {
final List<RecentProject> projects;
final String? selectedProjectId;
final ValueChanged<RecentProject>? onProjectSelected;
final bool desktop;
final bool projectScoped;
final ResourceSection resourceSection;
final ValueChanged<ResourceSection>? onResourceSectionChanged;
final String query;
final ValueChanged<String>? onQueryChanged;
final MediaSort sort;
final ValueChanged<MediaSort>? onSortChanged;
final MediaGridSize gridSize;
final ValueChanged<MediaGridSize>? onGridSizeChanged;
@override
State<MediaBrowserToolbar> createState() => _MediaBrowserToolbarState();
@@ -38,6 +60,25 @@ class MediaBrowserToolbar extends StatefulWidget {
class _MediaBrowserToolbarState extends State<MediaBrowserToolbar> {
Object? _filterConfiguration;
Widget? _filterControls;
final _search = TextEditingController();
@override
void initState() {
super.initState();
_search.text = widget.query;
}
@override
void didUpdateWidget(covariant MediaBrowserToolbar oldWidget) {
super.didUpdateWidget(oldWidget);
if (_search.text != widget.query) _search.text = widget.query;
}
@override
void dispose() {
_search.dispose();
super.dispose();
}
bool get canImport => widget.canImport;
VoidCallback get onImport => widget.onImport;
@@ -57,6 +98,11 @@ class _MediaBrowserToolbarState extends State<MediaBrowserToolbar> {
final configuration = (
filter,
grid,
widget.sort,
widget.gridSize,
widget.desktop,
widget.projectScoped,
canImport,
Theme.of(context),
Localizations.localeOf(context),
MediaQuery.textScalerOf(context),
@@ -69,13 +115,20 @@ class _MediaBrowserToolbarState extends State<MediaBrowserToolbar> {
final selected = projects
.where((project) => project.id == selectedProjectId)
.firstOrNull;
if (widget.desktop || AppTheme.isDesktop(context)) {
return _desktopToolbar(context, selected);
}
Widget row(Key key, Widget child) => SizedBox(
key: key,
height: AppControlSize.panelToolbar,
height: AppTheme.isDesktop(context)
? AppDesktopMetrics.panelHeader
: AppControlSize.panelToolbar,
child: Padding(
padding: const EdgeInsets.symmetric(
padding: EdgeInsets.symmetric(
horizontal: AppSidebarMetrics.outerPadding,
vertical: AppSpacing.gap,
vertical: AppTheme.isDesktop(context)
? AppSpacing.tiny
: AppSpacing.gap,
),
child: child,
),
@@ -87,85 +140,84 @@ class _MediaBrowserToolbarState extends State<MediaBrowserToolbar> {
row(
const Key('media-project-row'),
LayoutBuilder(
builder: (context, constraints) {
final painter = TextPainter(
text: TextSpan(
text: context.l10n.importMedia,
style: AppTheme.toolbarTextStyle(context),
builder: (context, constraints) => Row(
children: [
Expanded(
child: widget.projectScoped
? Text(
context.l10n.materials,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.titleSmall,
)
: AppDropdownMenu(
enabled:
onProjectSelected != null && projects.isNotEmpty,
maxHeight: 320,
items: [
for (final project in projects)
AppMenuItem(
key: ValueKey('media-project-${project.id}'),
label: project.name,
selected: project.id == selectedProjectId,
selectOption: true,
onPressed: onProjectSelected == null
? null
: () => onProjectSelected!(project),
),
],
builder: (context, toggle, focusNode) =>
AppToolbarDropdownButton(
buttonKey: const Key('media-project-button'),
focusNode: focusNode,
onPressed: toggle,
child: Row(
children: [
Expanded(
child: Text(
selected?.name ??
context.l10n.selectProject,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
const SizedBox(width: AppSpacing.tiny),
const Icon(
AppIcons.expandMore,
size: AppIconSize.header,
),
],
),
),
),
),
textDirection: Directionality.of(context),
textScaler: MediaQuery.textScalerOf(context),
)..layout();
final compact = constraints.maxWidth < painter.width + 140;
painter.dispose();
return Row(
children: [
Expanded(
child: AppDropdownMenu(
enabled: onProjectSelected != null && projects.isNotEmpty,
maxHeight: 320,
items: [
for (final project in projects)
AppMenuItem(
key: ValueKey('media-project-${project.id}'),
label: project.name,
selected: project.id == selectedProjectId,
selectOption: true,
onPressed: onProjectSelected == null
? null
: () => onProjectSelected!(project),
),
],
builder: (context, toggle, focusNode) =>
AppToolbarDropdownButton(
buttonKey: const Key('media-project-button'),
focusNode: focusNode,
onPressed: toggle,
child: Row(
children: [
Expanded(
child: Text(
selected?.name ??
context.l10n.selectProject,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
const SizedBox(width: AppSpacing.tiny),
const Icon(
Icons.keyboard_arrow_down,
size: AppIconSize.header,
),
],
),
),
const SizedBox(width: AppSpacing.tiny),
ConstrainedBox(
constraints: BoxConstraints(
maxWidth: (constraints.maxWidth * .45).clamp(
28,
double.infinity,
),
),
const SizedBox(width: AppSpacing.tiny),
if (compact)
SizedBox.square(
dimension: AppControlSize.headerButton,
child: IconButton(
key: const Key('media-import-button'),
tooltip: context.l10n.importMedia,
onPressed: canImport ? onImport : null,
icon: const Icon(Icons.add, size: AppIconSize.header),
),
)
else
SizedBox(
height: AppControlSize.headerButton,
child: TextButton.icon(
child: SizedBox(
height: AppControlSize.headerButton,
child: Tooltip(
message: context.l10n.importMedia,
child: TextButton(
key: const Key('media-import-button'),
style: AppTheme.toolbarButtonStyle(context),
onPressed: canImport ? onImport : null,
icon: const Icon(Icons.add, size: AppIconSize.header),
label: Text(context.l10n.importMedia),
child: Text(
context.l10n.importMedia,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
),
],
);
},
),
),
],
),
),
),
_filterControls ??= row(
@@ -206,7 +258,7 @@ class _MediaBrowserToolbarState extends State<MediaBrowserToolbar> {
),
const SizedBox(width: AppSpacing.tiny),
const Icon(
Icons.keyboard_arrow_down,
AppIcons.expandMore,
size: AppIconSize.header,
),
],
@@ -224,7 +276,7 @@ class _MediaBrowserToolbarState extends State<MediaBrowserToolbar> {
key: const Key('media-layout-toggle'),
onPressed: onToggleGrid,
icon: Icon(
grid ? Icons.view_list_outlined : Icons.grid_view_outlined,
grid ? AppIcons.listView : AppIcons.gridView,
size: AppIconSize.header,
),
tooltip: grid
@@ -238,4 +290,314 @@ class _MediaBrowserToolbarState extends State<MediaBrowserToolbar> {
],
);
}
Widget _desktopToolbar(BuildContext context, RecentProject? selected) {
Widget category() => Semantics(
label: context.l10n.mediaCategory,
child: AppDropdownMenu(
items: [
for (final option in MediaFilter.values)
AppMenuItem(
key: ValueKey('media-filter-${option.name}'),
label: option.label(context),
selected: option == filter,
selectOption: true,
onPressed: () => onFilterChanged(option),
),
],
builder: (context, toggle, focus) => AppToolbarDropdownButton(
buttonKey: const Key('media-category-button'),
focusNode: focus,
onPressed: toggle,
child: Row(
children: [
Expanded(
child: Text(
filter.label(context),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
const Icon(AppIcons.expandMore, size: 16),
],
),
),
),
);
String sortLabel(MediaSort value) => switch (value) {
MediaSort.importOrder => context.l10n.mediaSortImportOrder,
MediaSort.nameAscending => context.l10n.mediaSortNameAscending,
MediaSort.nameDescending => context.l10n.mediaSortNameDescending,
};
return Column(
key: const Key('media-panel-header'),
mainAxisSize: MainAxisSize.min,
children: [
if (widget.projectScoped)
ResourceSectionTabs(
selected: widget.resourceSection,
onSelected: widget.onResourceSectionChanged,
)
else
SizedBox(
key: const Key('media-project-row'),
height: 36,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
child: LayoutBuilder(
builder: (context, constraints) => Row(
children: [
Expanded(
child: AppDropdownMenu(
enabled:
onProjectSelected != null && projects.isNotEmpty,
maxHeight: 320,
items: [
for (final project in projects)
AppMenuItem(
key: ValueKey('media-project-${project.id}'),
label: project.name,
selected: project.id == selectedProjectId,
selectOption: true,
onPressed: onProjectSelected == null
? null
: () => onProjectSelected!(project),
),
],
builder: (context, toggle, focusNode) =>
AppToolbarDropdownButton(
buttonKey: const Key('media-project-button'),
focusNode: focusNode,
onPressed: toggle,
child: Row(
children: [
Expanded(
child: Text(
selected?.name ??
context.l10n.selectProject,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
const Icon(AppIcons.expandMore, size: 16),
],
),
),
),
),
const SizedBox(width: 4),
ConstrainedBox(
constraints: BoxConstraints(
maxWidth: (constraints.maxWidth * .45).clamp(
28,
double.infinity,
),
),
child: SizedBox(
height: 28,
child: Tooltip(
message: context.l10n.importMedia,
child: TextButton(
key: const Key('media-import-button'),
style: AppTheme.toolbarButtonStyle(context),
onPressed: canImport ? onImport : null,
child: Text(
context.l10n.importMedia,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
),
),
),
],
),
),
),
),
if (!widget.projectScoped ||
widget.resourceSection == ResourceSection.imported)
_filterControls ??= _desktopControls(context, category, sortLabel),
],
);
}
Widget _desktopControls(
BuildContext context,
Widget Function() category,
String Function(MediaSort) sortLabel,
) {
List<Widget> sortItems() => [
for (final value in MediaSort.values)
AppMenuItem(
key: ValueKey('media-sort-${value.name}'),
label: sortLabel(value),
selected: widget.sort == value,
selectOption: true,
onPressed: widget.onSortChanged == null
? null
: () => widget.onSortChanged!(value),
),
];
String sizeLabel(MediaGridSize value) => switch (value) {
MediaGridSize.small => context.l10n.mediaThumbnailSmall,
MediaGridSize.medium => context.l10n.mediaThumbnailMedium,
MediaGridSize.large => context.l10n.mediaThumbnailLarge,
};
List<Widget> sizeItems() => [
for (final value in MediaGridSize.values)
AppMenuItem(
key: ValueKey('media-size-${value.name}'),
label: sizeLabel(value),
selected: widget.gridSize == value,
selectOption: true,
onPressed: !grid || widget.onGridSizeChanged == null
? null
: () => widget.onGridSizeChanged!(value),
),
];
Widget menuButton({
required Key key,
required String tooltip,
required IconData icon,
required List<Widget> items,
}) => SizedBox.square(
dimension: 28,
child: AppDropdownMenu(
items: items,
builder: (context, toggle, focus) => IconButton(
key: key,
focusNode: focus,
tooltip: tooltip,
onPressed: toggle,
padding: EdgeInsets.zero,
icon: Icon(icon, size: 16),
),
),
);
return SizedBox(
key: const Key('media-filter-row'),
height: 40,
child: Padding(
padding: const EdgeInsets.fromLTRB(12, 4, 12, 4),
child: LayoutBuilder(
builder: (context, constraints) {
final wide = constraints.maxWidth >= 400;
return Row(
children: [
Expanded(
child: TextField(
key: const Key('media-search'),
controller: _search,
enabled: widget.onQueryChanged != null,
style: AppTheme.inputTextStyle(
context,
style: AppTheme.toolbarTextStyle(context),
),
cursorHeight: AppTheme.inputCursorHeight(
context,
style: AppTheme.toolbarTextStyle(context),
),
textAlignVertical: TextAlignVertical.center,
decoration: InputDecoration(
hintText: context.l10n.searchOptions(
context.l10n.materials,
),
hintStyle: AppTheme.inputHintStyle(
context,
style: AppTheme.toolbarTextStyle(context),
),
isDense: true,
constraints: const BoxConstraints(minHeight: 32),
contentPadding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 4,
),
prefixIcon: constraints.maxWidth < 160
? null
: const Icon(AppIcons.search, size: 16),
prefixIconConstraints: const BoxConstraints(
minWidth: 28,
minHeight: 28,
),
),
onChanged: (value) => widget.onQueryChanged?.call(value),
),
),
const SizedBox(width: 4),
if (wide) ...[
SizedBox(width: 88, height: 28, child: category()),
const SizedBox(width: 4),
menuButton(
key: const Key('media-sort-button'),
tooltip: context.l10n.sortMedia,
icon: AppIcons.sort,
items: sortItems(),
),
const SizedBox(width: 4),
menuButton(
key: const Key('media-size-button'),
tooltip: context.l10n.mediaThumbnailSize,
icon: AppIcons.gridView,
items: sizeItems(),
),
] else
menuButton(
key: const Key('media-category-button'),
tooltip: MaterialLocalizations.of(context).showMenuTooltip,
icon: AppIcons.more,
items: [
AppMenuLabel(context.l10n.mediaCategory),
for (final option in MediaFilter.values)
AppMenuItem(
key: ValueKey('media-filter-${option.name}'),
label: option.label(context),
selected: option == filter,
selectOption: true,
onPressed: () => onFilterChanged(option),
),
const AppMenuSeparator(),
AppMenuLabel(context.l10n.sortMedia),
...sortItems(),
const AppMenuSeparator(),
AppMenuLabel(context.l10n.mediaThumbnailSize),
...sizeItems(),
],
),
const SizedBox(width: 4),
SizedBox.square(
dimension: 28,
child: IconButton(
key: const Key('media-layout-toggle'),
onPressed: onToggleGrid,
padding: EdgeInsets.zero,
icon: Icon(
grid ? AppIcons.listView : AppIcons.gridView,
size: 16,
),
tooltip: grid
? context.l10n.listLayout
: context.l10n.gridLayout,
),
),
if (widget.projectScoped) ...[
const SizedBox(width: 4),
SizedBox.square(
dimension: 28,
child: IconButton(
key: const Key('media-import-button'),
onPressed: canImport ? () => onImport() : null,
tooltip: context.l10n.importMedia,
padding: EdgeInsets.zero,
icon: const Icon(AppIcons.add, size: 16),
),
),
],
],
);
},
),
),
);
}
}
@@ -0,0 +1,76 @@
import 'package:cutdex_ui/theme.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widget_previews.dart';
import '../../l10n/app_localizations.dart';
import '../../workspace/project_state.dart';
import 'media_browser_controller.dart';
import 'media_browser_toolbar.dart';
@Preview(
name: 'Media toolbar — light',
group: 'Desktop media',
size: Size(320, 76),
)
Widget desktopMediaToolbarLightPreview() => _preview(Brightness.light);
@Preview(
name: 'Media toolbar — dark',
group: 'Desktop media',
size: Size(240, 76),
)
@Preview(
name: 'Media toolbar — narrow',
group: 'Desktop media',
size: Size(180, 76),
)
Widget desktopMediaToolbarDarkPreview() => _preview(Brightness.dark);
@Preview(
name: 'Media toolbar — wide',
group: 'Desktop media',
size: Size(640, 76),
)
Widget desktopMediaToolbarWidePreview() => _preview(Brightness.light);
Widget _preview(Brightness brightness) {
var query = '';
var filter = MediaFilter.all;
var sort = MediaSort.importOrder;
var grid = true;
var gridSize = MediaGridSize.medium;
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: AppTheme.desktopWorkspaceTheme(
AppTheme.forPalette(AppPalette.graphite, brightness),
),
locale: const Locale('zh'),
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: Scaffold(
body: StatefulBuilder(
builder: (context, setState) => MediaBrowserToolbar(
desktop: true,
projects: const [
RecentProject(id: 'demo', name: '城市漫游', path: '/demo'),
RecentProject(id: 'other', name: '旅行记录', path: '/other'),
],
selectedProjectId: 'demo',
onProjectSelected: (_) {},
canImport: true,
onImport: () {},
filter: filter,
onFilterChanged: (value) => setState(() => filter = value),
grid: grid,
onToggleGrid: () => setState(() => grid = !grid),
query: query,
onQueryChanged: (value) => setState(() => query = value),
sort: sort,
onSortChanged: (value) => setState(() => sort = value),
gridSize: gridSize,
onGridSizeChanged: (value) => setState(() => gridSize = value),
),
),
),
);
}
+60 -7
View File
@@ -16,6 +16,7 @@ import 'media_browser_body.dart';
import 'media_browser_toolbar.dart';
import 'media_browser_controller.dart';
import 'media_browser_feedback.dart';
import 'resource_navigation.dart';
/// Desktop presentation owns compact controls and native file dragging.
class MediaPanel extends ConsumerStatefulWidget {
@@ -26,8 +27,10 @@ class MediaPanel extends ConsumerStatefulWidget {
this.grid,
this.onGridChanged,
this.onSelectProject,
this.projectScoped = false,
}) : assert((grid == null) == (onGridChanged == null));
final String? projectId;
final bool projectScoped;
final ValueChanged<RecentProject>? onSelectProject;
final Color? backgroundColor;
final bool? grid;
@@ -50,6 +53,7 @@ class _MediaPanelState extends ConsumerState<MediaPanel> {
grid: grid,
draggable: true,
compact: true,
desktop: true,
);
}
return _body!;
@@ -81,6 +85,8 @@ class _MediaPanelState extends ConsumerState<MediaPanel> {
child: Column(
children: [
MediaBrowserToolbar(
desktop: true,
projectScoped: widget.projectScoped,
projects: workspace.$1,
onProjectSelected: onSelectProject,
canImport: false,
@@ -96,18 +102,32 @@ class _MediaPanelState extends ConsumerState<MediaPanel> {
);
}
final browser = ref.watch(mediaBrowserProvider(projectId));
ref.watch(externalMediaImportProvider(projectId));
ref.watch(
externalMediaImportProvider(projectId).select((value) => value.isLoading),
);
final nativeDrop = ref.watch(platformCapabilitiesProvider).nativeFileDrop;
return ListenableSelector(
listenable: browser,
select: () =>
(browser.filter, browser.grid, browser.busy, browser.canImport),
select: () => (
browser.filter,
browser.grid,
browser.busy,
browser.importing,
browser.canImport,
browser.query,
browser.sort,
browser.gridSize,
browser.resourceSection,
),
builder: (context, _) {
final grid = widget.grid ?? browser.grid;
final visible =
TickerMode.valuesOf(context).enabled &&
(ModalRoute.of(context)?.isCurrent ?? true);
final enabled = browser.canImport && visible;
final browsingImports =
!widget.projectScoped ||
browser.resourceSection == ResourceSection.imported;
void toggleGrid() {
final next = !grid;
if (widget.onGridChanged case final onChanged?) {
@@ -128,6 +148,11 @@ class _MediaPanelState extends ConsumerState<MediaPanel> {
Column(
children: [
MediaBrowserToolbar(
desktop: true,
projectScoped: widget.projectScoped,
resourceSection: browser.resourceSection,
onResourceSectionChanged: (value) =>
browser.resourceSection = value,
projects: workspace.$1,
selectedProjectId: projectId,
onProjectSelected: onSelectProject,
@@ -137,21 +162,45 @@ class _MediaPanelState extends ConsumerState<MediaPanel> {
onFilterChanged: (value) => browser.filter = value,
grid: grid,
onToggleGrid: toggleGrid,
query: browser.query,
onQueryChanged: (value) => browser.query = value,
sort: browser.sort,
onSortChanged: (value) => browser.sort = value,
gridSize: browser.gridSize,
onGridSizeChanged: (value) => browser.gridSize = value,
),
Expanded(
key: const Key('media-panel-body'),
child: _browserBody(projectId, grid),
child: widget.projectScoped
? IndexedStack(
index: browsingImports ? 0 : 1,
children: [
TickerMode(
enabled: browsingImports,
child: _browserBody(projectId, grid),
),
ResourceLibraryEmpty(
key: ValueKey((
'resource-library-empty',
projectId,
browser.resourceSection,
)),
section: browser.resourceSection,
),
],
)
: _browserBody(projectId, grid),
),
],
),
if (browser.busy)
if (browser.importing)
const DelayedLoadingIndicator(
child: Align(
alignment: Alignment.topCenter,
child: LinearProgressIndicator(),
),
),
if (_hovering && enabled)
if (_hovering && enabled && browsingImports)
const DropToAddOverlay(key: Key('media-drop-highlight')),
],
),
@@ -159,7 +208,11 @@ class _MediaPanelState extends ConsumerState<MediaPanel> {
);
if (!nativeDrop) return content;
return NativeProjectDropRegion(
enabled: visible && browser.active && (enabled || browser.busy),
enabled:
browsingImports &&
visible &&
browser.active &&
(enabled || browser.busy),
onEnter: (_) {
if (enabled) setState(() => _hovering = true);
},
+208
View File
@@ -0,0 +1,208 @@
import 'package:cutdex_ui/icons.dart';
import 'package:cutdex_ui/theme.dart';
import 'package:cutdex_ui/widgets.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import '../../l10n/app_localizations.dart';
import 'resource_section.dart';
export 'resource_section.dart';
extension ResourceSectionPresentation on ResourceSection {
String label(AppLocalizations l10n) => switch (this) {
ResourceSection.imported => l10n.resourceMyMedia,
ResourceSection.audio => l10n.audio,
ResourceSection.text => l10n.text,
ResourceSection.stickers => l10n.resourceStickers,
ResourceSection.effects => l10n.resourceEffects,
ResourceSection.transitions => l10n.resourceTransitions,
};
IconData get icon => switch (this) {
ResourceSection.imported => AppIcons.mediaLibrary,
ResourceSection.audio => AppIcons.audio,
ResourceSection.text => AppIcons.rename,
ResourceSection.stickers => AppIcons.image,
ResourceSection.effects => AppIcons.assistant,
ResourceSection.transitions => AppIcons.splitVertical,
};
}
/// Desktop resource tabs share the timeline's scrolling and edge fades.
class ResourceSectionTabs extends StatefulWidget {
const ResourceSectionTabs({
super.key,
required this.selected,
required this.onSelected,
});
final ResourceSection selected;
final ValueChanged<ResourceSection>? onSelected;
@override
State<ResourceSectionTabs> createState() => _ResourceSectionTabsState();
}
class _ResourceSectionTabsState extends State<ResourceSectionTabs> {
final _scrollController = ScrollController();
final _selectedTabKey = GlobalKey();
@override
void initState() {
super.initState();
_showSelectedTab();
}
@override
void didUpdateWidget(covariant ResourceSectionTabs oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.selected != widget.selected) _showSelectedTab();
}
void _showSelectedTab() {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted) return;
final selected = _selectedTabKey.currentContext;
if (selected == null) return;
if (_scrollController.hasClients) {
final position = _scrollController.position;
if (widget.selected == ResourceSection.values.first) {
_scrollController.jumpTo(position.minScrollExtent);
return;
}
if (widget.selected == ResourceSection.values.last) {
_scrollController.jumpTo(position.maxScrollExtent);
return;
}
}
Scrollable.ensureVisible(
selected,
alignmentPolicy: ScrollPositionAlignmentPolicy.keepVisibleAtEnd,
);
Scrollable.ensureVisible(
selected,
alignmentPolicy: ScrollPositionAlignmentPolicy.keepVisibleAtStart,
);
});
}
void _onPointerSignal(PointerSignalEvent event) {
if (event is! PointerScrollEvent || !_scrollController.hasClients) return;
final delta = event.scrollDelta.dy != 0
? event.scrollDelta.dy
: event.scrollDelta.dx;
if (delta == 0) return;
final position = _scrollController.position;
final target = (position.pixels + delta).clamp(
position.minScrollExtent,
position.maxScrollExtent,
);
if (target == position.pixels) return;
GestureBinding.instance.pointerSignalResolver.register(event, (_) {
if (_scrollController.hasClients) _scrollController.jumpTo(target);
});
}
@override
void dispose() {
_scrollController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context)!;
return SizedBox(
key: const Key('resource-section-tabs'),
height: 36,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 5),
child: ScrollEdgeFade(
controller: _scrollController,
axis: Axis.horizontal,
child: Listener(
onPointerSignal: _onPointerSignal,
child: SingleChildScrollView(
key: const Key('resource-tabs-list'),
controller: _scrollController,
scrollDirection: Axis.horizontal,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 4),
child: Row(
children: [
for (final section in ResourceSection.values) ...[
if (section != ResourceSection.values.first)
const SizedBox(width: 4),
KeyedSubtree(
key: widget.selected == section
? _selectedTabKey
: null,
child: Semantics(
selected: widget.selected == section,
child: TextButton(
key: ValueKey('resource-tab-${section.name}'),
style: AppTheme.timelineTabStyle(
context,
selected: widget.selected == section,
),
onPressed: widget.onSelected == null
? null
: () => widget.onSelected!(section),
child: Text(section.label(l10n), maxLines: 1),
),
),
),
],
],
),
),
),
),
),
),
);
}
}
class ResourceLibraryEmpty extends StatelessWidget {
const ResourceLibraryEmpty({super.key, required this.section});
final ResourceSection section;
@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context)!;
final theme = Theme.of(context);
return Center(
child: SingleChildScrollView(
padding: const EdgeInsets.all(24),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
section.icon,
size: 28,
color: theme.colorScheme.onSurfaceVariant,
),
const SizedBox(height: 12),
Text(
l10n.resourceLibraryEmpty(section.label(l10n)),
textAlign: TextAlign.center,
style: theme.textTheme.bodyMedium,
),
if (section == ResourceSection.audio) ...[
const SizedBox(height: 6),
Text(
l10n.resourceImportedAudioHint,
textAlign: TextAlign.center,
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
),
],
],
),
),
);
}
}
@@ -0,0 +1,56 @@
import 'package:cutdex_ui/theme.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widget_previews.dart';
import '../../l10n/app_localizations.dart';
import 'resource_navigation.dart';
@Preview(
name: 'Resource categories — wide',
group: 'Desktop media',
size: Size(560, 260),
)
Widget wideResourceNavigationPreview() => _preview(Brightness.light);
@Preview(
name: 'Resource categories — narrow',
group: 'Desktop media',
size: Size(240, 260),
)
Widget narrowResourceNavigationPreview() => _preview(Brightness.dark);
Widget _preview(Brightness brightness) {
var section = ResourceSection.imported;
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: AppTheme.desktopWorkspaceTheme(
AppTheme.forPalette(AppPalette.graphite, brightness),
),
locale: const Locale('zh'),
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: Scaffold(
body: StatefulBuilder(
builder: (context, setState) => Column(
children: [
ResourceSectionTabs(
selected: section,
onSelected: (value) => setState(() => section = value),
),
const Divider(height: 1),
Expanded(
child: section == ResourceSection.imported
? Center(
child: Text(
AppLocalizations.of(context)!.dragMediaHint,
textAlign: TextAlign.center,
),
)
: ResourceLibraryEmpty(section: section),
),
],
),
),
),
);
}
+2
View File
@@ -0,0 +1,2 @@
/// Resource navigation is separate from filters on project-imported files.
enum ResourceSection { imported, audio, text, stickers, effects, transitions }
+16 -3
View File
@@ -1,3 +1,5 @@
import '../../shared/widgets/listenable_selector.dart';
import 'package:cutdex/l10n/l10n.dart';
import 'package:cutdex_sdk/project.dart';
@@ -11,6 +13,7 @@ import 'package:cutdex_ui/theme.dart';
import 'package:cutdex_ui/widgets.dart';
import '../../shared/widgets/confirm_resource_download_cancel.dart';
import '../../shared/widgets/error_notification_host.dart';
import '../../shared/widgets/processing_resource_download_dialog.dart';
import '../../workspace/timeline_session.dart';
@@ -268,11 +271,11 @@ class _TranscriptionDialogState extends ConsumerState<TranscriptionDialog> {
_closing = true;
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted) return;
final messenger = ScaffoldMessenger.maybeOf(context);
final notifications = ErrorNotificationHost.maybeOf(context);
final message = context.l10n.subtitleTaskStarted;
_dismissDialog();
if (next is SubtitleStarted) {
messenger?.showSnackBar(SnackBar(content: Text(message)));
notifications?.showMessage(content: Text(message));
}
});
}
@@ -280,8 +283,18 @@ class _TranscriptionDialogState extends ConsumerState<TranscriptionDialog> {
ref.listen(subtitleDownloadProvider, (_, next) => handleResult(next));
ref.listen(_startProvider, (_, next) => handleResult(next));
return ListenableBuilder(
return ListenableSelector<Object>(
listenable: widget.session,
select: () {
final service = widget.session.transcriptions;
return (
service?.recognitionAvailable,
service?.translationAvailable,
service?.tasks.any((task) => !task.terminal),
service?.translationTasks.any((task) => !task.terminal),
widget.session.acceptsEdits,
);
},
builder: (context, _) {
final service = widget.session.transcriptions;
if (service?.recognitionAvailable != true ||
@@ -1,6 +1,7 @@
import 'package:cutdex/l10n/l10n.dart';
import 'package:flutter/material.dart';
import 'package:cutdex_ui/icons.dart';
import 'package:cutdex_ui/theme.dart';
import '../../workspace/media_availability.dart';
@@ -34,7 +35,7 @@ class UnavailableMediaPlaceholder extends StatelessWidget {
mainAxisSize: MainAxisSize.min,
children: [
Icon(
Icons.broken_image_outlined,
AppIcons.imageUnavailable,
size: isPreview ? 32 : 24,
color: theme.colorScheme.error,
),
+3 -2
View File
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'media_asset_cover.dart';
import 'package:cutdex_ui/icons.dart';
import 'package:cutdex_ui/theme.dart';
class VisualAssetTile extends StatelessWidget {
@@ -25,8 +26,8 @@ class VisualAssetTile extends StatelessWidget {
fallback: Center(
child: Icon(
asset.metadata['kind'] == 'image'
? Icons.image_outlined
: Icons.movie_outlined,
? AppIcons.image
: AppIcons.video,
size: AppIconSize.emptyState,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),