Gitea CI / Assemble and validate CI artifacts (push) Successful in 1m47s
Gitea CI / Check code and tests (push) Successful in 7m15s
Gitea CI / Build Android APK (push) Successful in 4m6s
Gitea CI / Build Windows x64 app (push) Successful in 3m34s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m29s
Gitea CI / Gitea CI passed (push) Successful in 1s
Gitea Release / Prepare draft Release (push) Failing after 8s
Gitea Release / Upload Android to draft Release (push) Skipped
Gitea Release / Upload Windows to draft Release (push) Skipped
Gitea Release / Verify and publish Release (push) Skipped
815 lines
29 KiB
Dart
815 lines
29 KiB
Dart
import '../../shared/widgets/listenable_selector.dart';
|
|
|
|
import 'package:cutdex/shared/widgets/error_notification_host.dart';
|
|
import 'package:cutdex/errors/app_failure.dart';
|
|
|
|
import 'dart:math' as math;
|
|
|
|
import 'package:cutdex/l10n/l10n.dart';
|
|
import 'package:cutdex_core/project.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
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) {
|
|
MediaFilter.all => context.l10n.all,
|
|
MediaFilter.image => context.l10n.picture,
|
|
MediaFilter.video => context.l10n.video,
|
|
MediaFilter.audio => context.l10n.audio,
|
|
};
|
|
}
|
|
|
|
const maximumMediaGridTileWidth = 160.0;
|
|
const maximumCompactMediaGridTileWidth = 120.0;
|
|
|
|
class MediaBrowserBody extends ConsumerStatefulWidget {
|
|
const MediaBrowserBody({
|
|
super.key,
|
|
required this.projectId,
|
|
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();
|
|
}
|
|
|
|
@override
|
|
void didChangeAppLifecycleState(AppLifecycleState state) {
|
|
if (state == AppLifecycleState.resumed) {
|
|
ref.invalidate(mediaAvailabilityProvider);
|
|
}
|
|
}
|
|
|
|
MediaBrowserController get _browser =>
|
|
ref.read(mediaBrowserProvider(widget.projectId));
|
|
bool get _checkingDrop => _browser.busy;
|
|
String? get _selectedAssetId => _browser.selectedAssetId;
|
|
set _selectedAssetId(String? value) => _browser.selectedAssetId = value;
|
|
MediaFilter get _filter => _browser.filter;
|
|
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;
|
|
final failure =
|
|
ref.read(projectsProvider).asData?.value.error ??
|
|
const AppFailure(AppErrorCode.operationFailed);
|
|
ErrorNotificationHost.of(context)
|
|
.showFailure(failure, context.l10n.failureMessage(failure));
|
|
}
|
|
|
|
Future<void> _rename(AssetDocument asset) async {
|
|
final controller = TextEditingController(text: asset.name);
|
|
final name = await showAppDialog<String>(
|
|
context: context,
|
|
builder: (context) => AppDialog(
|
|
title: context.l10n.renameMedia,
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context),
|
|
child: Text(context.l10n.cancel),
|
|
),
|
|
ListenableBuilder(
|
|
listenable: controller,
|
|
builder: (context, _) => FilledButton(
|
|
onPressed: controller.text.trim().isEmpty
|
|
? null
|
|
: () => Navigator.pop(context, controller.text.trim()),
|
|
child: Text(context.l10n.save),
|
|
),
|
|
),
|
|
],
|
|
child: AppField(
|
|
label: context.l10n.name,
|
|
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());
|
|
}
|
|
},
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
// The route's closing animation can still read its text controller.
|
|
await Future<void>.delayed(const Duration(milliseconds: 200));
|
|
controller.dispose();
|
|
if (!mounted || name == null) return;
|
|
await _action(() => _browser.rename(asset, name));
|
|
}
|
|
|
|
Future<void> _remove(AssetDocument asset) async {
|
|
final confirmed = await showAppDialog<bool>(
|
|
context: context,
|
|
builder: (context) => AppDialog(
|
|
title: context.l10n.removeMedia,
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context, false),
|
|
child: Text(context.l10n.cancel),
|
|
),
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context, true),
|
|
style: TextButton.styleFrom(
|
|
foregroundColor: Theme.of(context).colorScheme.error,
|
|
),
|
|
child: Text(context.l10n.remove),
|
|
),
|
|
],
|
|
child: Text(context.l10n.removeMediaConfirmation(asset.name)),
|
|
),
|
|
);
|
|
if (!mounted || confirmed != true) return;
|
|
await _action(() => _browser.remove(asset));
|
|
}
|
|
|
|
@override
|
|
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) => (
|
|
value.value?.activeProject?.id,
|
|
value.value?.assets,
|
|
value.value?.timeline?.id,
|
|
value.value?.projectBusy,
|
|
),
|
|
),
|
|
);
|
|
final workspace = ref.read(projectsProvider).value;
|
|
final active = workspace?.activeProject?.id == widget.projectId;
|
|
final timelineId = active ? workspace?.timeline?.id : null;
|
|
final timeline = timelineId == null
|
|
? null
|
|
: ref
|
|
.watch(editorTimelineProvider(widget.projectId, timelineId))
|
|
.asData
|
|
?.value;
|
|
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 [];
|
|
}
|
|
Widget item(BuildContext context, int index) {
|
|
final asset = assets[index];
|
|
return Consumer(
|
|
builder: (context, ref, _) {
|
|
final availability = ref
|
|
.watch(mediaAvailabilityProvider(widget.projectId, asset))
|
|
.asData
|
|
?.value;
|
|
final unavailable =
|
|
availability != null &&
|
|
availability != MediaAvailability.available;
|
|
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: 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),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
final content = assets.isEmpty
|
|
? Center(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(AppSpacing.medium),
|
|
child: Text(
|
|
widget.desktop && _browser.query.trim().isNotEmpty
|
|
? context.l10n.noMatchingMedia
|
|
: _filter != MediaFilter.all
|
|
? context.l10n.noMediaOfType(_filter.label(context))
|
|
: _desktop
|
|
? context.l10n.dragMediaHint
|
|
: context.l10n.noMedia,
|
|
textAlign: TextAlign.center,
|
|
),
|
|
),
|
|
)
|
|
: LayoutBuilder(
|
|
builder: (context, constraints) {
|
|
final spacing = widget.desktop
|
|
? DesktopMediaMetrics.gap
|
|
: widget.compact
|
|
? AppSpacing.gap
|
|
: AppSpacing.small;
|
|
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.desktop
|
|
? DesktopMediaMetrics.columns(
|
|
width,
|
|
_browser.gridSize.targetWidth,
|
|
)
|
|
: widget.compact
|
|
? ((width + spacing) /
|
|
(maximumCompactMediaGridTileWidth + spacing))
|
|
.ceil()
|
|
: ((width + spacing) /
|
|
(maximumMediaGridTileWidth + spacing))
|
|
.ceil(),
|
|
);
|
|
final tileWidth = (width - spacing * (columns - 1)) / columns;
|
|
final textStyle = Theme.of(context).textTheme.bodySmall!;
|
|
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 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.custom(
|
|
key: PageStorageKey(('media-grid', widget.projectId)),
|
|
controller: controller,
|
|
semanticChildCount: assets.length,
|
|
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,
|
|
),
|
|
childrenDelegate: _MediaChildrenDelegate(
|
|
item,
|
|
childCount: assets.length,
|
|
),
|
|
);
|
|
if (widget.desktop) {
|
|
return ScrollEdgeFade(
|
|
controller: _desktopScroll,
|
|
child: scrollView(_desktopScroll),
|
|
);
|
|
}
|
|
return ScrollEdgeFadeBuilder(
|
|
key: ValueKey(('media-scroll-fade', widget.projectId, _isGrid)),
|
|
builder: scrollView,
|
|
);
|
|
},
|
|
);
|
|
if (!widget.desktop) return content;
|
|
return Column(
|
|
children: [
|
|
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
|
|
? AspectRatio(
|
|
aspectRatio: 16 / 9,
|
|
child: _isGrid
|
|
? UnavailableMediaPlaceholder(availability: availability)
|
|
: ColoredBox(
|
|
color: AppSurfaces.of(context).previewBackground,
|
|
child: Center(
|
|
child: Text(
|
|
availability == MediaAvailability.missing
|
|
? context.l10n.mediaMissing
|
|
: context.l10n.mediaUnavailable,
|
|
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
|
color: Theme.of(context).colorScheme.error,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
)
|
|
: !_isGrid &&
|
|
const {'audio', 'video', 'image'}.contains(asset.metadata['kind'])
|
|
? MediaAssetStrip(asset: asset)
|
|
: 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 Icon(AppIcons.file),
|
|
),
|
|
),
|
|
};
|
|
final name = Tooltip(
|
|
// Hover still shows the full name; touch long press belongs to actions.
|
|
triggerMode: TooltipTriggerMode.manual,
|
|
message: asset.name,
|
|
child: Text(
|
|
asset.name,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: Theme.of(context).textTheme.bodySmall,
|
|
),
|
|
);
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
ClipRRect(
|
|
borderRadius: BorderRadius.circular(6),
|
|
child: Stack(
|
|
children: [
|
|
if (!_isGrid)
|
|
SizedBox(height: MediaAssetStrip.height, child: cover)
|
|
else
|
|
cover,
|
|
Positioned(
|
|
top: 4,
|
|
right: 4,
|
|
child: MediaAssetDuration(asset: asset),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
SizedBox(height: widget.compact ? AppSpacing.gap : AppSpacing.small),
|
|
name,
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
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,
|
|
required this.draggable,
|
|
required this.onTap,
|
|
required this.child,
|
|
});
|
|
|
|
final bool selected;
|
|
final bool grid;
|
|
final bool desktop;
|
|
final MediaAssetDrag drag;
|
|
final String name;
|
|
final bool draggable;
|
|
final VoidCallback onTap;
|
|
final Widget child;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final selectionDecoration = BoxDecoration(
|
|
borderRadius: BorderRadius.circular(6),
|
|
border: Border.all(color: Theme.of(context).colorScheme.primary),
|
|
);
|
|
final tile = Semantics(
|
|
selected: selected,
|
|
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,
|
|
),
|
|
),
|
|
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,
|
|
maxSimultaneousDrags: draggable ? 1 : 0,
|
|
dragAnchorStrategy: pointerDragAnchorStrategy,
|
|
onDragStarted: onTap,
|
|
onDragEnd: (_) => drag.feedbackVisible.value = true,
|
|
feedback: ValueListenableBuilder<bool>(
|
|
valueListenable: drag.feedbackVisible,
|
|
builder: (context, visible, child) =>
|
|
visible ? child! : const SizedBox.shrink(),
|
|
child: Material(
|
|
elevation: 4,
|
|
color: Theme.of(context).colorScheme.surfaceContainerHigh,
|
|
child: SizedBox(
|
|
width: 144,
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(AppSpacing.small),
|
|
child: Text(
|
|
name,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: Theme.of(context).textTheme.bodySmall,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
child: tile,
|
|
);
|
|
}
|
|
}
|
|
|
|
// Constraint changes reflow existing cells without rebuilding menus and tiles.
|
|
// A new builder is created when assets, filters or the project change.
|
|
class _MediaChildrenDelegate extends SliverChildBuilderDelegate {
|
|
const _MediaChildrenDelegate(super.builder, {super.childCount});
|
|
|
|
@override
|
|
bool shouldRebuild(covariant _MediaChildrenDelegate oldDelegate) =>
|
|
builder != oldDelegate.builder || childCount != oldDelegate.childCount;
|
|
}
|