feat(workspace): 桌面工作区、主题与交互更新,发布 0.1.2
Gitea CI / Check code and tests (push) Successful in 6m37s
Gitea CI / Build Windows x64 app (push) Successful in 3m18s
Gitea CI / Build Android APK (push) Successful in 3m47s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m7s
Gitea CI / Assemble and validate CI artifacts (push) Successful in 50s
Gitea CI / Gitea CI passed (push) Successful in 2s
Gitea Release / Prepare draft Release (push) Successful in 9s
Gitea Release / Upload Android to draft Release (push) Successful in 16s
Gitea Release / Upload Windows to draft Release (push) Successful in 22s
Gitea Release / Verify and publish Release (push) Successful in 14s
Gitea CI / Check code and tests (push) Successful in 6m37s
Gitea CI / Build Windows x64 app (push) Successful in 3m18s
Gitea CI / Build Android APK (push) Successful in 3m47s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m7s
Gitea CI / Assemble and validate CI artifacts (push) Successful in 50s
Gitea CI / Gitea CI passed (push) Successful in 2s
Gitea Release / Prepare draft Release (push) Successful in 9s
Gitea Release / Upload Android to draft Release (push) Successful in 16s
Gitea Release / Upload Windows to draft Release (push) Successful in 22s
Gitea Release / Verify and publish Release (push) Successful in 14s
This commit was merged in pull request #13.
This commit is contained in:
1 parent
aa5255d1e4
commit
abc1868550
260 files changed
+43964
-5591
No files matched your search
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user