diff --git a/lib/features/media/desktop_media_asset_tile.dart b/lib/features/media/desktop_media_asset_tile.dart index 9236a2a..2dc7774 100644 --- a/lib/features/media/desktop_media_asset_tile.dart +++ b/lib/features/media/desktop_media_asset_tile.dart @@ -24,12 +24,23 @@ class DesktopMediaAssetTile extends StatelessWidget { final MediaAvailability? availability; static TextStyle? _nameStyle(BuildContext context) => - Theme.of(context).textTheme.bodyMedium - ?.copyWith(fontSize: 13, height: 20 / 13); + Theme.of(context).textTheme.bodyMedium?.copyWith( + 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) => - Theme.of(context).textTheme.bodySmall - ?.copyWith(fontSize: 12, height: 16 / 12); + Theme.of(context).textTheme.bodySmall?.copyWith( + 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. static double gridLabelHeight(BuildContext context) { @@ -106,7 +117,7 @@ class DesktopMediaAssetTile extends StatelessWidget { ); final cover = ClipRRect( key: ValueKey('desktop-media-cover-${asset.id}'), - borderRadius: BorderRadius.circular(4), + borderRadius: BorderRadius.circular(AppInspectorMetrics.radius), child: Stack( children: [ 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), - ), - ], - ], - ), - ); - }, - ), - ); -} diff --git a/lib/features/media/media_browser_body.dart b/lib/features/media/media_browser_body.dart index 8c1713c..ea085e9 100644 --- a/lib/features/media/media_browser_body.dart +++ b/lib/features/media/media_browser_body.dart @@ -298,6 +298,95 @@ class _MediaBrowserBodyState extends ConsumerState _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( @@ -382,105 +471,6 @@ class _MediaBrowserBodyState extends ConsumerState 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.desktop ? ListView.builder( @@ -509,9 +499,10 @@ class _MediaBrowserBodyState extends ConsumerState separatorBuilder: (_, _) => SizedBox(height: spacing), ) - : GridView.builder( + : GridView.custom( key: PageStorageKey(('media-grid', widget.projectId)), controller: controller, + semanticChildCount: assets.length, padding: EdgeInsets.all(padding), gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: columns, @@ -528,8 +519,10 @@ class _MediaBrowserBodyState extends ConsumerState labelHeight + 2, ), - itemCount: assets.length, - itemBuilder: item, + childrenDelegate: _MediaChildrenDelegate( + item, + childCount: assets.length, + ), ); if (widget.desktop) { return ScrollEdgeFade( @@ -546,8 +539,6 @@ class _MediaBrowserBodyState extends ConsumerState 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( @@ -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; +} diff --git a/lib/features/media/media_browser_controller.dart b/lib/features/media/media_browser_controller.dart index 09031fe..0cc9955 100644 --- a/lib/features/media/media_browser_controller.dart +++ b/lib/features/media/media_browser_controller.dart @@ -30,9 +30,9 @@ enum MediaSort { importOrder, nameAscending, nameDescending } /// Desktop thumbnail density, independent of touch-page presentation. enum MediaGridSize { - small(120), - medium(160), - large(200); + small(96), + medium(120), + large(160); const MediaGridSize(this.targetWidth); final double targetWidth; diff --git a/lib/features/media/media_browser_layout.dart b/lib/features/media/media_browser_layout.dart index 9fde431..bddf9fb 100644 --- a/lib/features/media/media_browser_layout.dart +++ b/lib/features/media/media_browser_layout.dart @@ -2,15 +2,14 @@ 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 padding = 16.0; static const gap = 8.0; - static const tilePadding = 5.0; + static const tilePadding = 8.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()); + math.max(1, ((width + gap) / (targetWidth + gap)).ceil()); static double gridExtent(double tileWidth, double labelHeight) => (tileWidth - tilePadding * 2) * 9 / 16 + @@ -19,7 +18,7 @@ abstract final class DesktopMediaMetrics { tilePadding * 2; } -/// Matching list-column visibility for a header and its asset rows. +/// List-column visibility within asset rows. final class DesktopMediaListColumns { const DesktopMediaListColumns(double width) : duration = width >= 240, diff --git a/lib/features/media/media_browser_toolbar.dart b/lib/features/media/media_browser_toolbar.dart index ea55d61..ca112b6 100644 --- a/lib/features/media/media_browser_toolbar.dart +++ b/lib/features/media/media_browser_toolbar.dart @@ -292,6 +292,34 @@ class _MediaBrowserToolbarState extends State { } 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( label: context.l10n.mediaCategory, child: AppDropdownMenu( @@ -309,6 +337,7 @@ class _MediaBrowserToolbarState extends State { buttonKey: const Key('media-category-button'), focusNode: focus, onPressed: toggle, + style: desktopButtonStyle, child: Row( children: [ Expanded( @@ -341,9 +370,14 @@ class _MediaBrowserToolbarState extends State { else SizedBox( key: const Key('media-project-row'), - height: 36, + height: AppInspectorMetrics.row, child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4), + padding: const EdgeInsetsDirectional.fromSTEB( + AppInspectorMetrics.padding, + AppInspectorMetrics.rowPadding, + AppInspectorMetrics.trailingPadding, + AppInspectorMetrics.rowPadding, + ), child: LayoutBuilder( builder: (context, constraints) => Row( children: [ @@ -369,6 +403,7 @@ class _MediaBrowserToolbarState extends State { buttonKey: const Key('media-project-button'), focusNode: focusNode, onPressed: toggle, + style: desktopButtonStyle, child: Row( children: [ Expanded( @@ -385,7 +420,7 @@ class _MediaBrowserToolbarState extends State { ), ), ), - const SizedBox(width: 4), + const SizedBox(width: AppSpacing.small), ConstrainedBox( constraints: BoxConstraints( maxWidth: (constraints.maxWidth * .45).clamp( @@ -394,12 +429,12 @@ class _MediaBrowserToolbarState extends State { ), ), child: SizedBox( - height: 28, + height: AppInspectorMetrics.input, child: Tooltip( message: context.l10n.importMedia, child: TextButton( key: const Key('media-import-button'), - style: AppTheme.toolbarButtonStyle(context), + style: desktopButtonStyle, onPressed: canImport ? onImport : null, child: Text( context.l10n.importMedia, @@ -427,6 +462,14 @@ class _MediaBrowserToolbarState extends State { Widget Function() category, 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 sortItems() => [ for (final value in MediaSort.values) AppMenuItem( @@ -462,7 +505,7 @@ class _MediaBrowserToolbarState extends State { required IconData icon, required List items, }) => SizedBox.square( - dimension: 28, + dimension: AppInspectorMetrics.action, child: AppDropdownMenu( items: items, builder: (context, toggle, focus) => IconButton( @@ -477,9 +520,14 @@ class _MediaBrowserToolbarState extends State { ); return SizedBox( key: const Key('media-filter-row'), - height: 40, + height: AppInspectorMetrics.row, child: Padding( - padding: const EdgeInsets.fromLTRB(12, 4, 12, 4), + padding: const EdgeInsets.fromLTRB( + AppInspectorMetrics.padding, + AppInspectorMetrics.rowPadding, + AppInspectorMetrics.trailingPadding, + AppInspectorMetrics.rowPadding, + ), child: LayoutBuilder( builder: (context, constraints) { final wide = constraints.maxWidth >= 400; @@ -490,13 +538,10 @@ class _MediaBrowserToolbarState extends State { key: const Key('media-search'), controller: _search, enabled: widget.onQueryChanged != null, - style: AppTheme.inputTextStyle( - context, - style: AppTheme.toolbarTextStyle(context), - ), + style: AppTheme.inputTextStyle(context, style: searchText), cursorHeight: AppTheme.inputCursorHeight( context, - style: AppTheme.toolbarTextStyle(context), + style: searchText, ), textAlignVertical: TextAlignVertical.center, decoration: InputDecoration( @@ -505,36 +550,61 @@ class _MediaBrowserToolbarState extends State { ), hintStyle: AppTheme.inputHintStyle( context, - style: AppTheme.toolbarTextStyle(context), + style: searchText, ), + filled: true, + fillColor: colors.surfaceContainer, isDense: true, - constraints: const BoxConstraints(minHeight: 32), + constraints: const BoxConstraints( + minHeight: AppInspectorMetrics.input, + ), contentPadding: const EdgeInsets.symmetric( - horizontal: 8, - vertical: 4, + horizontal: AppSpacing.small, + ), + 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 ? null : const Icon(AppIcons.search, size: 16), prefixIconConstraints: const BoxConstraints( - minWidth: 28, - minHeight: 28, + minWidth: AppInspectorMetrics.input, + minHeight: AppInspectorMetrics.input, ), ), onChanged: (value) => widget.onQueryChanged?.call(value), ), ), - const SizedBox(width: 4), + const SizedBox(width: AppSpacing.small), if (wide) ...[ - SizedBox(width: 88, height: 28, child: category()), - const SizedBox(width: 4), + SizedBox( + width: 88, + height: AppInspectorMetrics.input, + child: category(), + ), + const SizedBox(width: AppSpacing.small), menuButton( key: const Key('media-sort-button'), tooltip: context.l10n.sortMedia, icon: AppIcons.sort, items: sortItems(), ), - const SizedBox(width: 4), + const SizedBox(width: AppSpacing.small), menuButton( key: const Key('media-size-button'), tooltip: context.l10n.mediaThumbnailSize, @@ -564,9 +634,9 @@ class _MediaBrowserToolbarState extends State { ...sizeItems(), ], ), - const SizedBox(width: 4), + const SizedBox(width: AppSpacing.small), SizedBox.square( - dimension: 28, + dimension: AppInspectorMetrics.action, child: IconButton( key: const Key('media-layout-toggle'), onPressed: onToggleGrid, @@ -581,9 +651,9 @@ class _MediaBrowserToolbarState extends State { ), ), if (widget.projectScoped) ...[ - const SizedBox(width: 4), + const SizedBox(width: AppSpacing.small), SizedBox.square( - dimension: 28, + dimension: AppInspectorMetrics.action, child: IconButton( key: const Key('media-import-button'), onPressed: canImport ? () => onImport() : null, diff --git a/lib/features/media/resource_navigation.dart b/lib/features/media/resource_navigation.dart index c42163f..2e4cc3f 100644 --- a/lib/features/media/resource_navigation.dart +++ b/lib/features/media/resource_navigation.dart @@ -115,9 +115,13 @@ class _ResourceSectionTabsState extends State { final l10n = AppLocalizations.of(context)!; return SizedBox( key: const Key('resource-section-tabs'), - height: 36, + height: AppDesktopMetrics.timelineTabs, child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 5), + padding: const EdgeInsetsDirectional.only( + start: AppSpacing.small, + top: 4, + bottom: 4, + ), child: ScrollEdgeFade( controller: _scrollController, axis: Axis.horizontal, @@ -127,35 +131,30 @@ class _ResourceSectionTabsState extends State { 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), + child: Row( + children: [ + for (final section in ResourceSection.values) ...[ + if (section != ResourceSection.values.first) + const SizedBox(width: AppSpacing.tiny), + 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), ), ), - ], + ), ], - ), + ], ), ), ), diff --git a/test/media_panel_test.dart b/test/media_panel_test.dart index 08ef0c8..43e0fed 100644 --- a/test/media_panel_test.dart +++ b/test/media_panel_test.dart @@ -679,13 +679,13 @@ void main() { final sortButton = tester.getRect( find.byKey(const Key('media-sort-button')), ); - expect(header.height, 76); - expect(importButton.height, 28); + expect(header.height, 64); + expect(importButton.height, 24); expect(importButton.top - header.top, 4); - expect(header.right - importButton.right, 12); - expect(header.right - layoutButton.right, 12); + expect(header.right - importButton.right, 8); + expect(header.right - layoutButton.right, 8); 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 ValueKey('media-filter-image')), findsNothing); expect( @@ -793,7 +793,7 @@ void main() { (tester.widget(find.byType(GridView)).gridDelegate as SliverGridDelegateWithFixedCrossAxisCount) .crossAxisCount; - expect(columns(), 1); + expect(columns(), 2); expect( find.ancestor( of: find.byType(GridView), @@ -809,6 +809,18 @@ void main() { findsNothing, ); 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(find.byTooltip('列表布局')); await tester.pumpAndSettle(); @@ -841,14 +853,15 @@ void main() { await tester.pumpAndSettle(); for (final (width, count) in [ (120.0, 1), - (180.0, 1), - (220.0, 1), - (280.0, 1), - (240.0, 1), - (360.0, 2), - (520.0, 3), - (560.0, 3), - (900.0, 5), + (180.0, 2), + (220.0, 2), + (260.0, 2), + (280.0, 2), + (240.0, 2), + (360.0, 3), + (520.0, 4), + (560.0, 5), + (900.0, 7), ]) { await tester.binding.setSurfaceSize(Size(width, 600)); await tester.pumpAndSettle(); @@ -862,7 +875,7 @@ void main() { padding.horizontal - delegate.crossAxisSpacing * (count - 1)) / count; - expect(tileWidth, greaterThanOrEqualTo(width < 184 ? width - 24 : 160)); + expect(tileWidth, lessThanOrEqualTo(120)); expect(tester.takeException(), isNull); } expect( @@ -894,11 +907,11 @@ void main() { (tester.widget(find.byType(GridView)).gridDelegate as SliverGridDelegateWithFixedCrossAxisCount) .crossAxisCount; - expect(columns(), 4); + expect(columns(), 6); for (final (size, count) in [ - (MediaGridSize.small, 5), - (MediaGridSize.large, 3), - (MediaGridSize.medium, 4), + (MediaGridSize.small, 7), + (MediaGridSize.large, 5), + (MediaGridSize.medium, 6), ]) { await tester.tap(find.byKey(const Key('media-size-button'))); await tester.pumpAndSettle(); @@ -923,7 +936,7 @@ void main() { final container = await mount(tester); expect( tester.getSize(find.byKey(const Key('media-panel-header'))).height, - 76, + 64, ); expect( tester.getSize(find.byKey(const Key('media-search'))).width, @@ -1044,9 +1057,9 @@ void main() { browser.gridSize = size; await tester.pump(); final firstOffset = position().pixels; - expect(firstOffset, lessThanOrEqualTo(position().maxScrollExtent)); + expect(firstOffset, lessThanOrEqualTo(position().maxScrollExtent + 1e-6)); await tester.pumpAndSettle(); - expect(position().pixels, firstOffset); + expect(position().pixels, closeTo(firstOffset, 1e-6)); expect( tester .getRect(find.byKey(ValueKey(anchor.assetId))) diff --git a/test/resource_navigation_test.dart b/test/resource_navigation_test.dart index 72fc6a1..087af32 100644 --- a/test/resource_navigation_test.dart +++ b/test/resource_navigation_test.dart @@ -75,7 +75,7 @@ void main() { tester .getSize(find.byKey(const Key('resource-section-tabs'))) .height, - 36, + 32, ); final header = tester.getRect( find.byKey(const Key('resource-section-tabs')),