refactor(media): compact browsing controls and isolate asset row updates
This commit is contained in:
1 parent
1acfe4a005
commit
107e93b959
8 files changed
+287
-257
No files matched your search
@@ -24,12 +24,23 @@ class DesktopMediaAssetTile extends StatelessWidget {
|
|||||||
final MediaAvailability? availability;
|
final MediaAvailability? availability;
|
||||||
|
|
||||||
static TextStyle? _nameStyle(BuildContext context) =>
|
static TextStyle? _nameStyle(BuildContext context) =>
|
||||||
Theme.of(context).textTheme.bodyMedium
|
Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||||
?.copyWith(fontSize: 13, height: 20 / 13);
|
fontFamily: 'packages/cutdex_ui/Inter',
|
||||||
|
fontSize: AppInspectorMetrics.fontSize,
|
||||||
|
height: AppInspectorMetrics.lineHeight / AppInspectorMetrics.fontSize,
|
||||||
|
fontWeight: FontWeight.w500,
|
||||||
|
fontVariations: const [FontVariation('wght', 500)],
|
||||||
|
letterSpacing: AppInspectorMetrics.fontSize * .005,
|
||||||
|
);
|
||||||
|
|
||||||
static TextStyle? _metadataStyle(BuildContext context) =>
|
static TextStyle? _metadataStyle(BuildContext context) =>
|
||||||
Theme.of(context).textTheme.bodySmall
|
Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||||
?.copyWith(fontSize: 12, height: 16 / 12);
|
fontFamily: 'packages/cutdex_ui/Inter',
|
||||||
|
fontSize: AppInspectorMetrics.fontSize,
|
||||||
|
height: AppInspectorMetrics.lineHeight / AppInspectorMetrics.fontSize,
|
||||||
|
fontVariations: const [FontVariation('wght', 450)],
|
||||||
|
letterSpacing: AppInspectorMetrics.fontSize * .005,
|
||||||
|
);
|
||||||
|
|
||||||
/// Font fallback and fractional scaling can round a line above size × height.
|
/// Font fallback and fractional scaling can round a line above size × height.
|
||||||
static double gridLabelHeight(BuildContext context) {
|
static double gridLabelHeight(BuildContext context) {
|
||||||
@@ -106,7 +117,7 @@ class DesktopMediaAssetTile extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
final cover = ClipRRect(
|
final cover = ClipRRect(
|
||||||
key: ValueKey('desktop-media-cover-${asset.id}'),
|
key: ValueKey('desktop-media-cover-${asset.id}'),
|
||||||
borderRadius: BorderRadius.circular(4),
|
borderRadius: BorderRadius.circular(AppInspectorMetrics.radius),
|
||||||
child: Stack(
|
child: Stack(
|
||||||
children: [
|
children: [
|
||||||
if (unavailable)
|
if (unavailable)
|
||||||
@@ -215,66 +226,3 @@ class DesktopMediaAssetTile extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -298,6 +298,95 @@ class _MediaBrowserBodyState extends ConsumerState<MediaBrowserBody>
|
|||||||
_anchorOwner = null;
|
_anchorOwner = null;
|
||||||
_anchorAssets = const [];
|
_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
|
final content = assets.isEmpty
|
||||||
? Center(
|
? Center(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
@@ -382,105 +471,6 @@ class _MediaBrowserBodyState extends ConsumerState<MediaBrowserBody>
|
|||||||
height: constraints.maxHeight,
|
height: constraints.maxHeight,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
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),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget scrollView(ScrollController controller) => !_isGrid
|
Widget scrollView(ScrollController controller) => !_isGrid
|
||||||
? widget.desktop
|
? widget.desktop
|
||||||
? ListView.builder(
|
? ListView.builder(
|
||||||
@@ -509,9 +499,10 @@ class _MediaBrowserBodyState extends ConsumerState<MediaBrowserBody>
|
|||||||
separatorBuilder: (_, _) =>
|
separatorBuilder: (_, _) =>
|
||||||
SizedBox(height: spacing),
|
SizedBox(height: spacing),
|
||||||
)
|
)
|
||||||
: GridView.builder(
|
: GridView.custom(
|
||||||
key: PageStorageKey(('media-grid', widget.projectId)),
|
key: PageStorageKey(('media-grid', widget.projectId)),
|
||||||
controller: controller,
|
controller: controller,
|
||||||
|
semanticChildCount: assets.length,
|
||||||
padding: EdgeInsets.all(padding),
|
padding: EdgeInsets.all(padding),
|
||||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||||
crossAxisCount: columns,
|
crossAxisCount: columns,
|
||||||
@@ -528,8 +519,10 @@ class _MediaBrowserBodyState extends ConsumerState<MediaBrowserBody>
|
|||||||
labelHeight +
|
labelHeight +
|
||||||
2,
|
2,
|
||||||
),
|
),
|
||||||
itemCount: assets.length,
|
childrenDelegate: _MediaChildrenDelegate(
|
||||||
itemBuilder: item,
|
item,
|
||||||
|
childCount: assets.length,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
if (widget.desktop) {
|
if (widget.desktop) {
|
||||||
return ScrollEdgeFade(
|
return ScrollEdgeFade(
|
||||||
@@ -546,8 +539,6 @@ class _MediaBrowserBodyState extends ConsumerState<MediaBrowserBody>
|
|||||||
if (!widget.desktop) return content;
|
if (!widget.desktop) return content;
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
if (!_isGrid)
|
|
||||||
const DesktopMediaListHeader(key: Key('media-list-header')),
|
|
||||||
Expanded(child: content),
|
Expanded(child: content),
|
||||||
const Divider(height: 1),
|
const Divider(height: 1),
|
||||||
SizedBox(
|
SizedBox(
|
||||||
@@ -811,3 +802,13 @@ class _SelectableAsset extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
@@ -30,9 +30,9 @@ enum MediaSort { importOrder, nameAscending, nameDescending }
|
|||||||
|
|
||||||
/// Desktop thumbnail density, independent of touch-page presentation.
|
/// Desktop thumbnail density, independent of touch-page presentation.
|
||||||
enum MediaGridSize {
|
enum MediaGridSize {
|
||||||
small(120),
|
small(96),
|
||||||
medium(160),
|
medium(120),
|
||||||
large(200);
|
large(160);
|
||||||
|
|
||||||
const MediaGridSize(this.targetWidth);
|
const MediaGridSize(this.targetWidth);
|
||||||
final double targetWidth;
|
final double targetWidth;
|
||||||
|
|||||||
@@ -2,15 +2,14 @@ import 'dart:math' as math;
|
|||||||
|
|
||||||
/// Shared desktop geometry for cards, rows, headers and browse anchoring.
|
/// Shared desktop geometry for cards, rows, headers and browse anchoring.
|
||||||
abstract final class DesktopMediaMetrics {
|
abstract final class DesktopMediaMetrics {
|
||||||
static const padding = 12.0;
|
static const padding = 16.0;
|
||||||
static const gap = 8.0;
|
static const gap = 8.0;
|
||||||
static const tilePadding = 5.0;
|
static const tilePadding = 8.0;
|
||||||
static const listCover = 56.0;
|
static const listCover = 56.0;
|
||||||
static const listRow = 48.0;
|
static const listRow = 48.0;
|
||||||
static const listHeader = 28.0;
|
|
||||||
|
|
||||||
static int columns(double width, double targetWidth) =>
|
static int columns(double width, double targetWidth) =>
|
||||||
math.max(1, ((width + gap) / (targetWidth + gap)).floor());
|
math.max(1, ((width + gap) / (targetWidth + gap)).ceil());
|
||||||
|
|
||||||
static double gridExtent(double tileWidth, double labelHeight) =>
|
static double gridExtent(double tileWidth, double labelHeight) =>
|
||||||
(tileWidth - tilePadding * 2) * 9 / 16 +
|
(tileWidth - tilePadding * 2) * 9 / 16 +
|
||||||
@@ -19,7 +18,7 @@ abstract final class DesktopMediaMetrics {
|
|||||||
tilePadding * 2;
|
tilePadding * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Matching list-column visibility for a header and its asset rows.
|
/// List-column visibility within asset rows.
|
||||||
final class DesktopMediaListColumns {
|
final class DesktopMediaListColumns {
|
||||||
const DesktopMediaListColumns(double width)
|
const DesktopMediaListColumns(double width)
|
||||||
: duration = width >= 240,
|
: duration = width >= 240,
|
||||||
|
|||||||
@@ -292,6 +292,34 @@ class _MediaBrowserToolbarState extends State<MediaBrowserToolbar> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _desktopToolbar(BuildContext context, RecentProject? selected) {
|
Widget _desktopToolbar(BuildContext context, RecentProject? selected) {
|
||||||
|
final desktopButtonStyle = AppTheme.toolbarButtonStyle(context).copyWith(
|
||||||
|
textStyle: WidgetStatePropertyAll(
|
||||||
|
Theme.of(context).textTheme.bodyMedium!.copyWith(
|
||||||
|
fontFamily: 'packages/cutdex_ui/Inter',
|
||||||
|
fontSize: AppInspectorMetrics.fontSize,
|
||||||
|
height: AppInspectorMetrics.lineHeight / AppInspectorMetrics.fontSize,
|
||||||
|
fontWeight: FontWeight.w400,
|
||||||
|
fontVariations: const [FontVariation('wght', 450)],
|
||||||
|
letterSpacing: AppInspectorMetrics.fontSize * .005,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
minimumSize: const WidgetStatePropertyAll(
|
||||||
|
Size(0, AppInspectorMetrics.input),
|
||||||
|
),
|
||||||
|
maximumSize: const WidgetStatePropertyAll(
|
||||||
|
Size(double.infinity, AppInspectorMetrics.input),
|
||||||
|
),
|
||||||
|
padding: const WidgetStatePropertyAll(
|
||||||
|
EdgeInsets.symmetric(horizontal: AppSpacing.small),
|
||||||
|
),
|
||||||
|
shape: const WidgetStatePropertyAll(
|
||||||
|
RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.all(
|
||||||
|
Radius.circular(AppInspectorMetrics.radius),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
Widget category() => Semantics(
|
Widget category() => Semantics(
|
||||||
label: context.l10n.mediaCategory,
|
label: context.l10n.mediaCategory,
|
||||||
child: AppDropdownMenu(
|
child: AppDropdownMenu(
|
||||||
@@ -309,6 +337,7 @@ class _MediaBrowserToolbarState extends State<MediaBrowserToolbar> {
|
|||||||
buttonKey: const Key('media-category-button'),
|
buttonKey: const Key('media-category-button'),
|
||||||
focusNode: focus,
|
focusNode: focus,
|
||||||
onPressed: toggle,
|
onPressed: toggle,
|
||||||
|
style: desktopButtonStyle,
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
@@ -341,9 +370,14 @@ class _MediaBrowserToolbarState extends State<MediaBrowserToolbar> {
|
|||||||
else
|
else
|
||||||
SizedBox(
|
SizedBox(
|
||||||
key: const Key('media-project-row'),
|
key: const Key('media-project-row'),
|
||||||
height: 36,
|
height: AppInspectorMetrics.row,
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
|
padding: const EdgeInsetsDirectional.fromSTEB(
|
||||||
|
AppInspectorMetrics.padding,
|
||||||
|
AppInspectorMetrics.rowPadding,
|
||||||
|
AppInspectorMetrics.trailingPadding,
|
||||||
|
AppInspectorMetrics.rowPadding,
|
||||||
|
),
|
||||||
child: LayoutBuilder(
|
child: LayoutBuilder(
|
||||||
builder: (context, constraints) => Row(
|
builder: (context, constraints) => Row(
|
||||||
children: [
|
children: [
|
||||||
@@ -369,6 +403,7 @@ class _MediaBrowserToolbarState extends State<MediaBrowserToolbar> {
|
|||||||
buttonKey: const Key('media-project-button'),
|
buttonKey: const Key('media-project-button'),
|
||||||
focusNode: focusNode,
|
focusNode: focusNode,
|
||||||
onPressed: toggle,
|
onPressed: toggle,
|
||||||
|
style: desktopButtonStyle,
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
@@ -385,7 +420,7 @@ class _MediaBrowserToolbarState extends State<MediaBrowserToolbar> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 4),
|
const SizedBox(width: AppSpacing.small),
|
||||||
ConstrainedBox(
|
ConstrainedBox(
|
||||||
constraints: BoxConstraints(
|
constraints: BoxConstraints(
|
||||||
maxWidth: (constraints.maxWidth * .45).clamp(
|
maxWidth: (constraints.maxWidth * .45).clamp(
|
||||||
@@ -394,12 +429,12 @@ class _MediaBrowserToolbarState extends State<MediaBrowserToolbar> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
height: 28,
|
height: AppInspectorMetrics.input,
|
||||||
child: Tooltip(
|
child: Tooltip(
|
||||||
message: context.l10n.importMedia,
|
message: context.l10n.importMedia,
|
||||||
child: TextButton(
|
child: TextButton(
|
||||||
key: const Key('media-import-button'),
|
key: const Key('media-import-button'),
|
||||||
style: AppTheme.toolbarButtonStyle(context),
|
style: desktopButtonStyle,
|
||||||
onPressed: canImport ? onImport : null,
|
onPressed: canImport ? onImport : null,
|
||||||
child: Text(
|
child: Text(
|
||||||
context.l10n.importMedia,
|
context.l10n.importMedia,
|
||||||
@@ -427,6 +462,14 @@ class _MediaBrowserToolbarState extends State<MediaBrowserToolbar> {
|
|||||||
Widget Function() category,
|
Widget Function() category,
|
||||||
String Function(MediaSort) sortLabel,
|
String Function(MediaSort) sortLabel,
|
||||||
) {
|
) {
|
||||||
|
final searchText = Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||||
|
fontFamily: 'packages/cutdex_ui/Inter',
|
||||||
|
fontSize: AppInspectorMetrics.fontSize,
|
||||||
|
height: AppInspectorMetrics.lineHeight / AppInspectorMetrics.fontSize,
|
||||||
|
fontVariations: const [FontVariation('wght', 450)],
|
||||||
|
letterSpacing: AppInspectorMetrics.fontSize * .005,
|
||||||
|
);
|
||||||
|
final colors = Theme.of(context).colorScheme;
|
||||||
List<Widget> sortItems() => [
|
List<Widget> sortItems() => [
|
||||||
for (final value in MediaSort.values)
|
for (final value in MediaSort.values)
|
||||||
AppMenuItem(
|
AppMenuItem(
|
||||||
@@ -462,7 +505,7 @@ class _MediaBrowserToolbarState extends State<MediaBrowserToolbar> {
|
|||||||
required IconData icon,
|
required IconData icon,
|
||||||
required List<Widget> items,
|
required List<Widget> items,
|
||||||
}) => SizedBox.square(
|
}) => SizedBox.square(
|
||||||
dimension: 28,
|
dimension: AppInspectorMetrics.action,
|
||||||
child: AppDropdownMenu(
|
child: AppDropdownMenu(
|
||||||
items: items,
|
items: items,
|
||||||
builder: (context, toggle, focus) => IconButton(
|
builder: (context, toggle, focus) => IconButton(
|
||||||
@@ -477,9 +520,14 @@ class _MediaBrowserToolbarState extends State<MediaBrowserToolbar> {
|
|||||||
);
|
);
|
||||||
return SizedBox(
|
return SizedBox(
|
||||||
key: const Key('media-filter-row'),
|
key: const Key('media-filter-row'),
|
||||||
height: 40,
|
height: AppInspectorMetrics.row,
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.fromLTRB(12, 4, 12, 4),
|
padding: const EdgeInsets.fromLTRB(
|
||||||
|
AppInspectorMetrics.padding,
|
||||||
|
AppInspectorMetrics.rowPadding,
|
||||||
|
AppInspectorMetrics.trailingPadding,
|
||||||
|
AppInspectorMetrics.rowPadding,
|
||||||
|
),
|
||||||
child: LayoutBuilder(
|
child: LayoutBuilder(
|
||||||
builder: (context, constraints) {
|
builder: (context, constraints) {
|
||||||
final wide = constraints.maxWidth >= 400;
|
final wide = constraints.maxWidth >= 400;
|
||||||
@@ -490,13 +538,10 @@ class _MediaBrowserToolbarState extends State<MediaBrowserToolbar> {
|
|||||||
key: const Key('media-search'),
|
key: const Key('media-search'),
|
||||||
controller: _search,
|
controller: _search,
|
||||||
enabled: widget.onQueryChanged != null,
|
enabled: widget.onQueryChanged != null,
|
||||||
style: AppTheme.inputTextStyle(
|
style: AppTheme.inputTextStyle(context, style: searchText),
|
||||||
context,
|
|
||||||
style: AppTheme.toolbarTextStyle(context),
|
|
||||||
),
|
|
||||||
cursorHeight: AppTheme.inputCursorHeight(
|
cursorHeight: AppTheme.inputCursorHeight(
|
||||||
context,
|
context,
|
||||||
style: AppTheme.toolbarTextStyle(context),
|
style: searchText,
|
||||||
),
|
),
|
||||||
textAlignVertical: TextAlignVertical.center,
|
textAlignVertical: TextAlignVertical.center,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
@@ -505,36 +550,61 @@ class _MediaBrowserToolbarState extends State<MediaBrowserToolbar> {
|
|||||||
),
|
),
|
||||||
hintStyle: AppTheme.inputHintStyle(
|
hintStyle: AppTheme.inputHintStyle(
|
||||||
context,
|
context,
|
||||||
style: AppTheme.toolbarTextStyle(context),
|
style: searchText,
|
||||||
),
|
),
|
||||||
|
filled: true,
|
||||||
|
fillColor: colors.surfaceContainer,
|
||||||
isDense: true,
|
isDense: true,
|
||||||
constraints: const BoxConstraints(minHeight: 32),
|
constraints: const BoxConstraints(
|
||||||
|
minHeight: AppInspectorMetrics.input,
|
||||||
|
),
|
||||||
contentPadding: const EdgeInsets.symmetric(
|
contentPadding: const EdgeInsets.symmetric(
|
||||||
horizontal: 8,
|
horizontal: AppSpacing.small,
|
||||||
vertical: 4,
|
),
|
||||||
|
border: const OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.all(
|
||||||
|
Radius.circular(AppInspectorMetrics.radius),
|
||||||
|
),
|
||||||
|
borderSide: BorderSide.none,
|
||||||
|
),
|
||||||
|
enabledBorder: const OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.all(
|
||||||
|
Radius.circular(AppInspectorMetrics.radius),
|
||||||
|
),
|
||||||
|
borderSide: BorderSide.none,
|
||||||
|
),
|
||||||
|
focusedBorder: OutlineInputBorder(
|
||||||
|
borderRadius: const BorderRadius.all(
|
||||||
|
Radius.circular(AppInspectorMetrics.radius),
|
||||||
|
),
|
||||||
|
borderSide: BorderSide(color: colors.primary),
|
||||||
),
|
),
|
||||||
prefixIcon: constraints.maxWidth < 160
|
prefixIcon: constraints.maxWidth < 160
|
||||||
? null
|
? null
|
||||||
: const Icon(AppIcons.search, size: 16),
|
: const Icon(AppIcons.search, size: 16),
|
||||||
prefixIconConstraints: const BoxConstraints(
|
prefixIconConstraints: const BoxConstraints(
|
||||||
minWidth: 28,
|
minWidth: AppInspectorMetrics.input,
|
||||||
minHeight: 28,
|
minHeight: AppInspectorMetrics.input,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
onChanged: (value) => widget.onQueryChanged?.call(value),
|
onChanged: (value) => widget.onQueryChanged?.call(value),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 4),
|
const SizedBox(width: AppSpacing.small),
|
||||||
if (wide) ...[
|
if (wide) ...[
|
||||||
SizedBox(width: 88, height: 28, child: category()),
|
SizedBox(
|
||||||
const SizedBox(width: 4),
|
width: 88,
|
||||||
|
height: AppInspectorMetrics.input,
|
||||||
|
child: category(),
|
||||||
|
),
|
||||||
|
const SizedBox(width: AppSpacing.small),
|
||||||
menuButton(
|
menuButton(
|
||||||
key: const Key('media-sort-button'),
|
key: const Key('media-sort-button'),
|
||||||
tooltip: context.l10n.sortMedia,
|
tooltip: context.l10n.sortMedia,
|
||||||
icon: AppIcons.sort,
|
icon: AppIcons.sort,
|
||||||
items: sortItems(),
|
items: sortItems(),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 4),
|
const SizedBox(width: AppSpacing.small),
|
||||||
menuButton(
|
menuButton(
|
||||||
key: const Key('media-size-button'),
|
key: const Key('media-size-button'),
|
||||||
tooltip: context.l10n.mediaThumbnailSize,
|
tooltip: context.l10n.mediaThumbnailSize,
|
||||||
@@ -564,9 +634,9 @@ class _MediaBrowserToolbarState extends State<MediaBrowserToolbar> {
|
|||||||
...sizeItems(),
|
...sizeItems(),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(width: 4),
|
const SizedBox(width: AppSpacing.small),
|
||||||
SizedBox.square(
|
SizedBox.square(
|
||||||
dimension: 28,
|
dimension: AppInspectorMetrics.action,
|
||||||
child: IconButton(
|
child: IconButton(
|
||||||
key: const Key('media-layout-toggle'),
|
key: const Key('media-layout-toggle'),
|
||||||
onPressed: onToggleGrid,
|
onPressed: onToggleGrid,
|
||||||
@@ -581,9 +651,9 @@ class _MediaBrowserToolbarState extends State<MediaBrowserToolbar> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (widget.projectScoped) ...[
|
if (widget.projectScoped) ...[
|
||||||
const SizedBox(width: 4),
|
const SizedBox(width: AppSpacing.small),
|
||||||
SizedBox.square(
|
SizedBox.square(
|
||||||
dimension: 28,
|
dimension: AppInspectorMetrics.action,
|
||||||
child: IconButton(
|
child: IconButton(
|
||||||
key: const Key('media-import-button'),
|
key: const Key('media-import-button'),
|
||||||
onPressed: canImport ? () => onImport() : null,
|
onPressed: canImport ? () => onImport() : null,
|
||||||
|
|||||||
@@ -115,9 +115,13 @@ class _ResourceSectionTabsState extends State<ResourceSectionTabs> {
|
|||||||
final l10n = AppLocalizations.of(context)!;
|
final l10n = AppLocalizations.of(context)!;
|
||||||
return SizedBox(
|
return SizedBox(
|
||||||
key: const Key('resource-section-tabs'),
|
key: const Key('resource-section-tabs'),
|
||||||
height: 36,
|
height: AppDesktopMetrics.timelineTabs,
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 5),
|
padding: const EdgeInsetsDirectional.only(
|
||||||
|
start: AppSpacing.small,
|
||||||
|
top: 4,
|
||||||
|
bottom: 4,
|
||||||
|
),
|
||||||
child: ScrollEdgeFade(
|
child: ScrollEdgeFade(
|
||||||
controller: _scrollController,
|
controller: _scrollController,
|
||||||
axis: Axis.horizontal,
|
axis: Axis.horizontal,
|
||||||
@@ -127,35 +131,30 @@ class _ResourceSectionTabsState extends State<ResourceSectionTabs> {
|
|||||||
key: const Key('resource-tabs-list'),
|
key: const Key('resource-tabs-list'),
|
||||||
controller: _scrollController,
|
controller: _scrollController,
|
||||||
scrollDirection: Axis.horizontal,
|
scrollDirection: Axis.horizontal,
|
||||||
child: Padding(
|
child: Row(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 4),
|
children: [
|
||||||
child: Row(
|
for (final section in ResourceSection.values) ...[
|
||||||
children: [
|
if (section != ResourceSection.values.first)
|
||||||
for (final section in ResourceSection.values) ...[
|
const SizedBox(width: AppSpacing.tiny),
|
||||||
if (section != ResourceSection.values.first)
|
KeyedSubtree(
|
||||||
const SizedBox(width: 4),
|
key: widget.selected == section ? _selectedTabKey : null,
|
||||||
KeyedSubtree(
|
child: Semantics(
|
||||||
key: widget.selected == section
|
selected: widget.selected == section,
|
||||||
? _selectedTabKey
|
child: TextButton(
|
||||||
: null,
|
key: ValueKey('resource-tab-${section.name}'),
|
||||||
child: Semantics(
|
style: AppTheme.timelineTabStyle(
|
||||||
selected: widget.selected == section,
|
context,
|
||||||
child: TextButton(
|
selected: widget.selected == section,
|
||||||
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),
|
|
||||||
),
|
),
|
||||||
|
onPressed: widget.onSelected == null
|
||||||
|
? null
|
||||||
|
: () => widget.onSelected!(section),
|
||||||
|
child: Text(section.label(l10n), maxLines: 1),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
],
|
],
|
||||||
),
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
+35
-22
@@ -679,13 +679,13 @@ void main() {
|
|||||||
final sortButton = tester.getRect(
|
final sortButton = tester.getRect(
|
||||||
find.byKey(const Key('media-sort-button')),
|
find.byKey(const Key('media-sort-button')),
|
||||||
);
|
);
|
||||||
expect(header.height, 76);
|
expect(header.height, 64);
|
||||||
expect(importButton.height, 28);
|
expect(importButton.height, 24);
|
||||||
expect(importButton.top - header.top, 4);
|
expect(importButton.top - header.top, 4);
|
||||||
expect(header.right - importButton.right, 12);
|
expect(header.right - importButton.right, 8);
|
||||||
expect(header.right - layoutButton.right, 12);
|
expect(header.right - layoutButton.right, 8);
|
||||||
expect(sortButton.top, layoutButton.top);
|
expect(sortButton.top, layoutButton.top);
|
||||||
expect(layoutButton.left - sortButton.right, 36);
|
expect(layoutButton.left - sortButton.right, 40);
|
||||||
expect(find.byKey(const Key('media-category-button')), findsOneWidget);
|
expect(find.byKey(const Key('media-category-button')), findsOneWidget);
|
||||||
expect(find.byKey(const ValueKey('media-filter-image')), findsNothing);
|
expect(find.byKey(const ValueKey('media-filter-image')), findsNothing);
|
||||||
expect(
|
expect(
|
||||||
@@ -793,7 +793,7 @@ void main() {
|
|||||||
(tester.widget<GridView>(find.byType(GridView)).gridDelegate
|
(tester.widget<GridView>(find.byType(GridView)).gridDelegate
|
||||||
as SliverGridDelegateWithFixedCrossAxisCount)
|
as SliverGridDelegateWithFixedCrossAxisCount)
|
||||||
.crossAxisCount;
|
.crossAxisCount;
|
||||||
expect(columns(), 1);
|
expect(columns(), 2);
|
||||||
expect(
|
expect(
|
||||||
find.ancestor(
|
find.ancestor(
|
||||||
of: find.byType(GridView),
|
of: find.byType(GridView),
|
||||||
@@ -809,6 +809,18 @@ void main() {
|
|||||||
findsNothing,
|
findsNothing,
|
||||||
);
|
);
|
||||||
final first = find.text('very-long-asset-name-0.png');
|
final first = find.text('very-long-asset-name-0.png');
|
||||||
|
final firstTile = find.byKey(
|
||||||
|
const ValueKey('/originals/very-long-asset-name-0.png'),
|
||||||
|
);
|
||||||
|
final tileWidget = tester.widget(firstTile);
|
||||||
|
await tester.binding.setSurfaceSize(const Size(520, 600));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(columns(), 4);
|
||||||
|
expect(tester.widget(firstTile), same(tileWidget));
|
||||||
|
await tester.binding.setSurfaceSize(const Size(280, 600));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(columns(), 2);
|
||||||
|
expect(tester.widget(firstTile), same(tileWidget));
|
||||||
await tester.tap(first);
|
await tester.tap(first);
|
||||||
await tester.tap(find.byTooltip('列表布局'));
|
await tester.tap(find.byTooltip('列表布局'));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
@@ -841,14 +853,15 @@ void main() {
|
|||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
for (final (width, count) in [
|
for (final (width, count) in [
|
||||||
(120.0, 1),
|
(120.0, 1),
|
||||||
(180.0, 1),
|
(180.0, 2),
|
||||||
(220.0, 1),
|
(220.0, 2),
|
||||||
(280.0, 1),
|
(260.0, 2),
|
||||||
(240.0, 1),
|
(280.0, 2),
|
||||||
(360.0, 2),
|
(240.0, 2),
|
||||||
(520.0, 3),
|
(360.0, 3),
|
||||||
(560.0, 3),
|
(520.0, 4),
|
||||||
(900.0, 5),
|
(560.0, 5),
|
||||||
|
(900.0, 7),
|
||||||
]) {
|
]) {
|
||||||
await tester.binding.setSurfaceSize(Size(width, 600));
|
await tester.binding.setSurfaceSize(Size(width, 600));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
@@ -862,7 +875,7 @@ void main() {
|
|||||||
padding.horizontal -
|
padding.horizontal -
|
||||||
delegate.crossAxisSpacing * (count - 1)) /
|
delegate.crossAxisSpacing * (count - 1)) /
|
||||||
count;
|
count;
|
||||||
expect(tileWidth, greaterThanOrEqualTo(width < 184 ? width - 24 : 160));
|
expect(tileWidth, lessThanOrEqualTo(120));
|
||||||
expect(tester.takeException(), isNull);
|
expect(tester.takeException(), isNull);
|
||||||
}
|
}
|
||||||
expect(
|
expect(
|
||||||
@@ -894,11 +907,11 @@ void main() {
|
|||||||
(tester.widget<GridView>(find.byType(GridView)).gridDelegate
|
(tester.widget<GridView>(find.byType(GridView)).gridDelegate
|
||||||
as SliverGridDelegateWithFixedCrossAxisCount)
|
as SliverGridDelegateWithFixedCrossAxisCount)
|
||||||
.crossAxisCount;
|
.crossAxisCount;
|
||||||
expect(columns(), 4);
|
expect(columns(), 6);
|
||||||
for (final (size, count) in [
|
for (final (size, count) in [
|
||||||
(MediaGridSize.small, 5),
|
(MediaGridSize.small, 7),
|
||||||
(MediaGridSize.large, 3),
|
(MediaGridSize.large, 5),
|
||||||
(MediaGridSize.medium, 4),
|
(MediaGridSize.medium, 6),
|
||||||
]) {
|
]) {
|
||||||
await tester.tap(find.byKey(const Key('media-size-button')));
|
await tester.tap(find.byKey(const Key('media-size-button')));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
@@ -923,7 +936,7 @@ void main() {
|
|||||||
final container = await mount(tester);
|
final container = await mount(tester);
|
||||||
expect(
|
expect(
|
||||||
tester.getSize(find.byKey(const Key('media-panel-header'))).height,
|
tester.getSize(find.byKey(const Key('media-panel-header'))).height,
|
||||||
76,
|
64,
|
||||||
);
|
);
|
||||||
expect(
|
expect(
|
||||||
tester.getSize(find.byKey(const Key('media-search'))).width,
|
tester.getSize(find.byKey(const Key('media-search'))).width,
|
||||||
@@ -1044,9 +1057,9 @@ void main() {
|
|||||||
browser.gridSize = size;
|
browser.gridSize = size;
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
final firstOffset = position().pixels;
|
final firstOffset = position().pixels;
|
||||||
expect(firstOffset, lessThanOrEqualTo(position().maxScrollExtent));
|
expect(firstOffset, lessThanOrEqualTo(position().maxScrollExtent + 1e-6));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(position().pixels, firstOffset);
|
expect(position().pixels, closeTo(firstOffset, 1e-6));
|
||||||
expect(
|
expect(
|
||||||
tester
|
tester
|
||||||
.getRect(find.byKey(ValueKey(anchor.assetId)))
|
.getRect(find.byKey(ValueKey(anchor.assetId)))
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ void main() {
|
|||||||
tester
|
tester
|
||||||
.getSize(find.byKey(const Key('resource-section-tabs')))
|
.getSize(find.byKey(const Key('resource-section-tabs')))
|
||||||
.height,
|
.height,
|
||||||
36,
|
32,
|
||||||
);
|
);
|
||||||
final header = tester.getRect(
|
final header = tester.getRect(
|
||||||
find.byKey(const Key('resource-section-tabs')),
|
find.byKey(const Key('resource-section-tabs')),
|
||||||
|
|||||||
Reference in new issue
Block a user