From 2d2aeea4de46b1a52641e7796a07dc3d7c9bc8cd Mon Sep 17 00:00:00 2001 From: zarzet <42882290+zarzet@users.noreply.github.com> Date: Wed, 21 Oct 2026 23:22:07 +0700 Subject: [PATCH] fix(desktop): put delete beside Remove RG in the selection toolbar The desktop selection toolbar left Remove RG and the delete button each alone on a row. Delete is now a compact toolbar pill, filled with the error role, that shares a row with Remove RG, delete first. Phones keep the full-width delete button. --- lib/widgets/library_track_selection_bar.dart | 95 +++++++++++--------- lib/widgets/selection_action_button.dart | 19 ++-- test/selection_action_grid_test.dart | 52 +++++++++++ 3 files changed, 121 insertions(+), 45 deletions(-) diff --git a/lib/widgets/library_track_selection_bar.dart b/lib/widgets/library_track_selection_bar.dart index 0be96942c..4cb66068b 100644 --- a/lib/widgets/library_track_selection_bar.dart +++ b/lib/widgets/library_track_selection_bar.dart @@ -43,28 +43,16 @@ class LibraryTrackSelectionBar extends StatelessWidget { Widget build(BuildContext context) { final colorScheme = Theme.of(context).colorScheme; final hasSelection = selectedCount > 0; - final delete = AppActionButton( - isDestructive: true, - onPressed: hasSelection ? onDelete : null, - icon: const Icon(Icons.delete_outline), - label: Text( - hasSelection - ? context.l10n.selectionDeleteTracksCount(selectedCount) - : context.l10n.selectionSelectToDelete, - ), - fontSize: isDesktopPlatform ? 14 : 17, - style: FilledButton.styleFrom( - backgroundColor: hasSelection - ? colorScheme.error - : colorScheme.surfaceContainerHighest, - foregroundColor: hasSelection - ? colorScheme.onError - : colorScheme.onSurfaceVariant, - padding: isDesktopPlatform - ? const EdgeInsets.symmetric(horizontal: 16, vertical: 8) - : const EdgeInsets.symmetric(vertical: 16), - shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)), - ), + final deleteLabel = hasSelection + ? context.l10n.selectionDeleteTracksCount(selectedCount) + : context.l10n.selectionSelectToDelete; + Widget replayGain({required bool remove}) => SelectionActionButton( + icon: remove ? Icons.remove_circle_outline : Icons.graphic_eq, + label: remove + ? context.l10n.selectionRemoveReplayGainCount(selectedCount) + : context.l10n.selectionReplayGainCount(selectedCount), + onPressed: hasSelection ? () => onReplayGain(remove: remove) : null, + colorScheme: colorScheme, ); return SelectionBottomBar( selectedCount: selectedCount, @@ -100,26 +88,53 @@ class LibraryTrackSelectionBar extends StatelessWidget { onPressed: hasSelection ? onConvert : null, colorScheme: colorScheme, ), - for (final remove in [false, true]) - SelectionActionButton( - icon: remove ? Icons.remove_circle_outline : Icons.graphic_eq, - label: remove - ? context.l10n.selectionRemoveReplayGainCount(selectedCount) - : context.l10n.selectionReplayGainCount(selectedCount), - onPressed: hasSelection - ? () => onReplayGain(remove: remove) - : null, - colorScheme: colorScheme, - ), + replayGain(remove: false), + // Desktop keeps delete a toolbar button. It shares a row with + // the other removal, delete first, so neither wraps onto a row + // of its own. + if (isDesktopPlatform) + Row( + mainAxisSize: MainAxisSize.min, + spacing: 8, + children: [ + SelectionActionButton( + icon: Icons.delete_outline, + label: deleteLabel, + onPressed: hasSelection ? onDelete : null, + colorScheme: colorScheme, + destructive: true, + ), + replayGain(remove: true), + ], + ) + else + replayGain(remove: true), ], ), - const SizedBox(height: 8), - // Desktop keeps the destructive action at its own width, as a - // toolbar button, instead of a full-width sheet button. - if (isDesktopPlatform) - Align(alignment: AlignmentDirectional.centerStart, child: delete) - else - SizedBox(width: double.infinity, child: delete), + if (!isDesktopPlatform) ...[ + const SizedBox(height: 8), + SizedBox( + width: double.infinity, + child: AppActionButton( + isDestructive: true, + onPressed: hasSelection ? onDelete : null, + icon: const Icon(Icons.delete_outline), + label: Text(deleteLabel), + style: FilledButton.styleFrom( + backgroundColor: hasSelection + ? colorScheme.error + : colorScheme.surfaceContainerHighest, + foregroundColor: hasSelection + ? colorScheme.onError + : colorScheme.onSurfaceVariant, + padding: const EdgeInsets.symmetric(vertical: 16), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(16), + ), + ), + ), + ), + ], ], ); } diff --git a/lib/widgets/selection_action_button.dart b/lib/widgets/selection_action_button.dart index 9c655c2be..d80aab6b9 100644 --- a/lib/widgets/selection_action_button.dart +++ b/lib/widgets/selection_action_button.dart @@ -45,20 +45,25 @@ class SelectionActionButton extends StatelessWidget { final VoidCallback? onPressed; final ColorScheme colorScheme; + /// Fills the button as the destructive action, such as delete. + final bool destructive; + const SelectionActionButton({ super.key, required this.icon, required this.label, required this.onPressed, required this.colorScheme, + this.destructive = false, }); @override Widget build(BuildContext context) { if (context.isMornye) { return AppActionButton( - outlined: true, - tonal: true, + outlined: !destructive, + tonal: !destructive, + isDestructive: destructive, onPressed: onPressed, icon: Icon(icon), label: Text(label, maxLines: 2, overflow: TextOverflow.ellipsis), @@ -75,12 +80,16 @@ class SelectionActionButton extends StatelessWidget { onTap: onPressed, excludeSemantics: true, child: ExpressiveButton( - tonal: true, + tonal: !destructive, onPressed: onPressed, icon: Icon(icon, size: 18), style: FilledButton.styleFrom( - backgroundColor: colorScheme.secondaryContainer, - foregroundColor: colorScheme.onSecondaryContainer, + backgroundColor: destructive + ? colorScheme.error + : colorScheme.secondaryContainer, + foregroundColor: destructive + ? colorScheme.onError + : colorScheme.onSecondaryContainer, minimumSize: compact ? const Size(0, 40) : Size(48, context.tokens.minTouchTarget), diff --git a/test/selection_action_grid_test.dart b/test/selection_action_grid_test.dart index f3fc8e805..40b2404fb 100644 --- a/test/selection_action_grid_test.dart +++ b/test/selection_action_grid_test.dart @@ -3,6 +3,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mornye/l10n/l10n.dart'; import 'package:mornye/theme/mornye_theme.dart'; +import 'package:mornye/utils/desktop_platform.dart'; import 'package:mornye/widgets/library_track_selection_bar.dart'; import 'package:mornye/widgets/selection_action_button.dart'; @@ -128,5 +129,56 @@ void main() { expect(tester.takeException(), isNull); } }); + + testWidgets('desktop delete leads the Remove RG row ($mornye)', ( + tester, + ) async { + debugDesktopPlatformOverride = true; + addTearDown(() => debugDesktopPlatformOverride = null); + tester.view.physicalSize = const Size(1280, 800); + tester.view.devicePixelRatio = 1; + addTearDown(tester.view.reset); + var deleted = false; + await tester.pumpWidget( + _app( + mornye, + Align( + alignment: Alignment.bottomCenter, + child: LibraryTrackSelectionBar( + selectedCount: 1, + allSelected: false, + onClose: () {}, + onToggleSelectAll: () {}, + bottomPadding: 0, + onReEnrich: () {}, + onConvert: () {}, + onReplayGain: ({required remove}) {}, + onDelete: () => deleted = true, + ), + ), + ), + ); + await tester.pumpAndSettle(); + Rect button(IconData icon) => tester.getRect( + find.byWidgetPredicate( + (widget) => widget is SelectionActionButton && widget.icon == icon, + ), + ); + final delete = button(Icons.delete_outline); + final removeGain = button(Icons.remove_circle_outline); + // Same row and height, delete on the leading side. + expect(delete.top, removeGain.top); + expect(delete.height, removeGain.height); + expect(delete.right, lessThan(removeGain.left)); + // Nothing sits alone below the row. + final lowest = tester + .widgetList(find.byType(SelectionActionButton)) + .map((widget) => button(widget.icon).top) + .reduce((a, b) => a > b ? a : b); + expect(lowest, delete.top); + await tester.tap(find.text('Delete 1 track')); + expect(deleted, isTrue); + expect(tester.takeException(), isNull); + }); } }