mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-11-21 20:00:49 +01:00
feat(desktop): expand the Material rail and list playlists in it
Wide windows now open with the rail expanded. A menu button on top and the sidebar shortcut toggle it, and the choice is kept across launches. Collapsed, the rail shows icons alone, named by tooltips. Expanded, its pills span the rail, and a Playlists section (All Playlists and the user's playlists) fills the space under the destinations. Library returns to the Library root while a playlist is open.
This commit is contained in:
1 parent
1158d0881b
commit
a985ea0e87
6 files changed
+511
-142
No files matched your search
@@ -38,6 +38,8 @@ import 'package:mornye/screens/now_playing_screen.dart';
|
||||
import 'package:mornye/utils/desktop_platform.dart';
|
||||
import 'package:mornye/utils/local_library_scan_prefs.dart';
|
||||
import 'package:mornye/utils/logger.dart';
|
||||
import 'package:mornye/widgets/desktop/desktop_commands.dart'
|
||||
show restoreDesktopSidebar;
|
||||
import 'package:mornye/widgets/desktop/desktop_inspector.dart'
|
||||
show bindDesktopFullScreenLyrics;
|
||||
import 'package:mornye/widgets/desktop/desktop_window.dart'
|
||||
@@ -142,6 +144,7 @@ void main() {
|
||||
safValidation = _startSafTreeValidation(bootstrapSettings);
|
||||
}
|
||||
musicPlayerRuntime.configure(bootstrapSettings);
|
||||
if (isDesktopPlatform) restoreDesktopSidebar(prefs);
|
||||
final bootstrapTheme = loadBootstrapThemeSettings(prefs);
|
||||
final initialSafAccessLost = await _detectInitialSafAccessLoss(
|
||||
safValidation,
|
||||
|
||||
@@ -148,7 +148,7 @@ class _MainShellState extends ConsumerState<MainShell>
|
||||
late final _PreviewStopNavigatorObserver _searchPreviewStopObserver;
|
||||
|
||||
/// Desktop: whether Library shows its root page, so the Mornye sidebar
|
||||
/// returns to the Library root's link.
|
||||
/// returns to the Library root's link and the Material rail to Library.
|
||||
late final _libraryDepthObserver = _PageDepthObserver(
|
||||
onRoot: () => desktopSidebarLink.value = null,
|
||||
);
|
||||
@@ -702,7 +702,7 @@ class _MainShellState extends ConsumerState<MainShell>
|
||||
];
|
||||
}
|
||||
|
||||
/// The page a Mornye desktop sidebar link opens in the Library tab, or
|
||||
/// The page a desktop sidebar or rail link opens in the Library tab, or
|
||||
/// null for the Library root.
|
||||
Widget? _desktopLibraryPage(String id) {
|
||||
const playlistPrefix = 'playlist:';
|
||||
@@ -737,8 +737,9 @@ class _MainShellState extends ConsumerState<MainShell>
|
||||
};
|
||||
}
|
||||
|
||||
/// Shows a Library page or playlist picked in the Mornye desktop sidebar
|
||||
/// in the Library tab, in place of the page it showed.
|
||||
/// Shows a Library page or playlist picked in the Mornye desktop sidebar,
|
||||
/// or a playlist picked in the Material rail, in the Library tab, in place
|
||||
/// of the page it showed.
|
||||
void _openDesktopLibraryLink(String id) {
|
||||
_onShellTabRequested(ShellTab.library);
|
||||
final page = _desktopLibraryPage(id);
|
||||
@@ -1060,7 +1061,8 @@ class _MainShellState extends ConsumerState<MainShell>
|
||||
libraryLinks: mornye
|
||||
? _desktopLibraryLinks(queueCount: queueState)
|
||||
: const [],
|
||||
onOpenLibraryLink: mornye ? _openDesktopLibraryLink : null,
|
||||
// The Material rail opens playlists alone.
|
||||
onOpenLibraryLink: _openDesktopLibraryLink,
|
||||
onOpenProfile: mornye ? _openDesktopProfile : null,
|
||||
// The selection bar floats over the pages, not the sidebar.
|
||||
body: SelectionOverlayHost(child: pageView),
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:mornye/l10n/l10n.dart';
|
||||
import 'package:mornye/services/shell_navigation_service.dart';
|
||||
import 'package:mornye/utils/desktop_platform.dart';
|
||||
@@ -231,9 +234,27 @@ List<ShellTab> desktopDestinationTabs({
|
||||
ShellTab.settings,
|
||||
];
|
||||
|
||||
/// Whether the Material desktop rail is collapsed, as it starts. Kept for the
|
||||
/// app session; the sidebar shortcut toggles it.
|
||||
final desktopSidebarCollapsed = ValueNotifier<bool>(true);
|
||||
const _sidebarCollapsedKey = 'desktop_sidebar_collapsed';
|
||||
|
||||
/// Whether the Material desktop rail is collapsed. Wide windows start with
|
||||
/// it expanded; the sidebar shortcut toggles it and the choice is kept.
|
||||
final desktopSidebarCollapsed = ValueNotifier<bool>(false);
|
||||
|
||||
/// Restores the rail state [toggleDesktopSidebar] last saved.
|
||||
void restoreDesktopSidebar(SharedPreferences prefs) =>
|
||||
desktopSidebarCollapsed.value =
|
||||
prefs.getBool(_sidebarCollapsedKey) ?? false;
|
||||
|
||||
/// Collapses or expands the Material rail and remembers the choice.
|
||||
void toggleDesktopSidebar() {
|
||||
final collapsed = desktopSidebarCollapsed.value =
|
||||
!desktopSidebarCollapsed.value;
|
||||
unawaited(
|
||||
SharedPreferences.getInstance().then(
|
||||
(prefs) => prefs.setBool(_sidebarCollapsedKey, collapsed),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Opens Now Playing in the content pane. Lyrics and Up Next live in the
|
||||
/// trailing inspector, toggled with [toggleDesktopInspector].
|
||||
|
||||
@@ -55,6 +55,10 @@ class DesktopSidebarLink {
|
||||
|
||||
/// The link that opens the list of every playlist.
|
||||
static const allPlaylistsId = 'playlists';
|
||||
|
||||
/// The Library root, which the Material rail's Library destination opens
|
||||
/// while a link is open.
|
||||
static const libraryRootId = 'library';
|
||||
}
|
||||
|
||||
/// The Library link open in the Mornye sidebar, or null for the Library
|
||||
@@ -128,7 +132,8 @@ class DesktopShellLayout extends StatelessWidget {
|
||||
/// The first stands for the Library destination itself.
|
||||
final List<DesktopSidebarLink> libraryLinks;
|
||||
|
||||
/// Mornye: opens a Library link or a playlist from the sidebar.
|
||||
/// Opens a Library link or a playlist from the Mornye sidebar, or a
|
||||
/// playlist from the expanded Material rail.
|
||||
final ValueChanged<String>? onOpenLibraryLink;
|
||||
|
||||
/// Mornye: opens the profile from the sidebar's account row.
|
||||
@@ -292,21 +297,26 @@ class DesktopShellLayout extends StatelessWidget {
|
||||
width: desktopWindowControlsWidth,
|
||||
child: DesktopWindowDragArea(zoomOnDoubleClick: true),
|
||||
),
|
||||
// Collapsed by default and always below
|
||||
// [desktopExpandedRailBreakpoint]; the sidebar shortcut
|
||||
// expands it in wider windows.
|
||||
// Expanded by default and always collapsed below
|
||||
// [desktopExpandedRailBreakpoint]; the rail's menu
|
||||
// button and the sidebar shortcut toggle it in wider
|
||||
// windows.
|
||||
Expanded(
|
||||
child: ValueListenableBuilder<bool>(
|
||||
valueListenable: desktopSidebarCollapsed,
|
||||
builder: (context, collapsed, _) =>
|
||||
DesktopNavigationRail(
|
||||
destinations: destinations,
|
||||
selected: selected,
|
||||
onSelected: onSelected,
|
||||
extended:
|
||||
!collapsed &&
|
||||
width >= desktopExpandedRailBreakpoint,
|
||||
),
|
||||
builder: (context, collapsed, _) {
|
||||
final wide = width >= desktopExpandedRailBreakpoint;
|
||||
return DesktopNavigationRail(
|
||||
destinations: destinations,
|
||||
selected: selected,
|
||||
onSelected: onSelected,
|
||||
extended: !collapsed && wide,
|
||||
onToggleExtended: wide
|
||||
? toggleDesktopSidebar
|
||||
: null,
|
||||
onOpenLibraryLink: onOpenLibraryLink,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -475,7 +485,9 @@ int _positionOf(List<DesktopDestination> destinations, ShellTab tab) =>
|
||||
|
||||
/// Material 3 Expressive navigation rail for desktop windows: collapsed, or
|
||||
/// expanded to [desktopSidebarWidth] when [extended], with Settings anchored
|
||||
/// at the bottom.
|
||||
/// at the bottom. A menu button on top toggles it when [onToggleExtended] is
|
||||
/// set. Expanded, the user's playlists follow the destinations when
|
||||
/// [onOpenLibraryLink] opens them.
|
||||
class DesktopNavigationRail extends StatelessWidget {
|
||||
const DesktopNavigationRail({
|
||||
super.key,
|
||||
@@ -483,6 +495,8 @@ class DesktopNavigationRail extends StatelessWidget {
|
||||
required this.selected,
|
||||
required this.onSelected,
|
||||
required this.extended,
|
||||
this.onToggleExtended,
|
||||
this.onOpenLibraryLink,
|
||||
});
|
||||
|
||||
final List<DesktopDestination> destinations;
|
||||
@@ -490,6 +504,42 @@ class DesktopNavigationRail extends StatelessWidget {
|
||||
final ValueChanged<ShellTab> onSelected;
|
||||
final bool extended;
|
||||
|
||||
/// Collapses or expands the rail; null hides the menu button, as in
|
||||
/// windows too narrow for the expanded rail.
|
||||
final VoidCallback? onToggleExtended;
|
||||
|
||||
/// Opens a playlist ([DesktopSidebarLink.playlistId]) or the list of them
|
||||
/// ([DesktopSidebarLink.allPlaylistsId]) in the Library tab.
|
||||
final ValueChanged<String>? onOpenLibraryLink;
|
||||
|
||||
Widget _menuButton(BuildContext context) {
|
||||
final toggle = onToggleExtended!;
|
||||
return AppIconButton(
|
||||
key: const ValueKey('desktop-rail-menu'),
|
||||
tooltip: desktopTooltip(
|
||||
context,
|
||||
context.l10n.desktopShortcutToggleSidebar,
|
||||
DesktopCommand.toggleSidebar,
|
||||
),
|
||||
icon: AppIcon(extended ? Icons.menu_open : Icons.menu),
|
||||
onPressed: toggle,
|
||||
);
|
||||
}
|
||||
|
||||
/// Library leaves an open playlist for the Library root, as the root link
|
||||
/// does in the Mornye sidebar; switching tabs alone would show the
|
||||
/// playlist again.
|
||||
void _select(ShellTab tab) {
|
||||
final openLink = onOpenLibraryLink;
|
||||
if (tab == ShellTab.library &&
|
||||
openLink != null &&
|
||||
desktopSidebarLink.value != null) {
|
||||
openLink(DesktopSidebarLink.libraryRootId);
|
||||
} else {
|
||||
onSelected(tab);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
@@ -500,12 +550,12 @@ class DesktopNavigationRail extends StatelessWidget {
|
||||
return NavigationRail(
|
||||
extended: extended,
|
||||
minExtendedWidth: desktopSidebarWidth,
|
||||
labelType: extended
|
||||
? NavigationRailLabelType.none
|
||||
: NavigationRailLabelType.all,
|
||||
// Collapsed, the rail shows icons alone.
|
||||
labelType: NavigationRailLabelType.none,
|
||||
backgroundColor: background,
|
||||
leading: onToggleExtended == null ? null : _menuButton(context),
|
||||
selectedIndex: index < 0 ? null : index,
|
||||
onDestinationSelected: (index) => onSelected(destinations[index].tab),
|
||||
onDestinationSelected: (index) => _select(destinations[index].tab),
|
||||
destinations: [
|
||||
for (final destination in destinations)
|
||||
NavigationRailDestination(
|
||||
@@ -531,70 +581,238 @@ class DesktopNavigationRail extends StatelessWidget {
|
||||
context,
|
||||
const AppMotionSpec(Duration(milliseconds: 300), Curves.easeInOutCubic),
|
||||
);
|
||||
final openLink = onOpenLibraryLink;
|
||||
// One expansion value drives the width, every pill and every label, so
|
||||
// the rail morphs continuously instead of swapping layouts at the end.
|
||||
return TweenAnimationBuilder<double>(
|
||||
tween: Tween(end: extended ? 1 : 0),
|
||||
duration: motion.duration,
|
||||
curve: motion.curve,
|
||||
builder: (context, expansion, _) {
|
||||
Widget item(DesktopDestination destination) => _RailDestination(
|
||||
key: ValueKey('desktop-rail:${destination.tab.name}'),
|
||||
destination: destination,
|
||||
selected: destination.tab == selected,
|
||||
expansion: expansion,
|
||||
onTap: () => onSelected(destination.tab),
|
||||
);
|
||||
final gap = lerpDouble(4, desktopRailItemGap, expansion)!;
|
||||
return ColoredBox(
|
||||
color: background,
|
||||
child: SizedBox(
|
||||
width: lerpDouble(
|
||||
desktopCollapsedRailWidth,
|
||||
desktopSidebarWidth,
|
||||
expansion,
|
||||
),
|
||||
child: ClipRect(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: Column(
|
||||
children: [
|
||||
for (final (index, destination)
|
||||
in primary.indexed) ...[
|
||||
if (index > 0) SizedBox(height: gap),
|
||||
item(destination),
|
||||
builder: (context, expansion, _) => ValueListenableBuilder<String?>(
|
||||
valueListenable: desktopSidebarLink,
|
||||
builder: (context, openId, _) {
|
||||
// An open playlist takes the selection from Library, as a link
|
||||
// does in the Mornye sidebar.
|
||||
final linkId = openLink != null && selected == ShellTab.library
|
||||
? openId
|
||||
: null;
|
||||
Widget item(DesktopDestination destination) => _RailDestination(
|
||||
key: ValueKey('desktop-rail:${destination.tab.name}'),
|
||||
destination: destination,
|
||||
selected: destination.tab == selected && linkId == null,
|
||||
expansion: expansion,
|
||||
onTap: () => _select(destination.tab),
|
||||
);
|
||||
final gap = lerpDouble(4, desktopRailItemGap, expansion)!;
|
||||
final playlistsShown = (expansion * 2 - 1).clamp(0.0, 1.0);
|
||||
return ColoredBox(
|
||||
color: background,
|
||||
child: SizedBox(
|
||||
width: lerpDouble(
|
||||
desktopCollapsedRailWidth,
|
||||
desktopSidebarWidth,
|
||||
expansion,
|
||||
),
|
||||
child: ClipRect(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (onToggleExtended != null)
|
||||
// Centered over the collapsed rail, where it stays,
|
||||
// in line with the destination icons.
|
||||
SizedBox(
|
||||
width: desktopCollapsedRailWidth,
|
||||
height: 56,
|
||||
child: Center(child: _menuButton(context)),
|
||||
),
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.only(top: 8, bottom: 8),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
for (final (index, destination)
|
||||
in primary.indexed) ...[
|
||||
if (index > 0) SizedBox(height: gap),
|
||||
item(destination),
|
||||
],
|
||||
if (openLink != null && playlistsShown > 0)
|
||||
Opacity(
|
||||
opacity: playlistsShown,
|
||||
child: _RailPlaylists(
|
||||
openId: linkId,
|
||||
onOpen: openLink,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (settings != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 16),
|
||||
child: item(settings),
|
||||
),
|
||||
],
|
||||
if (settings != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 16),
|
||||
child: item(settings),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// The expanded Material rail's Playlists section: a heading, All Playlists
|
||||
/// and the user's playlists as full-width 44dp rows, the desktop list
|
||||
/// density, so the rail lists what it can open instead of leaving the space
|
||||
/// under the destinations empty.
|
||||
class _RailPlaylists extends ConsumerWidget {
|
||||
const _RailPlaylists({required this.openId, required this.onOpen});
|
||||
|
||||
/// The open link, which shows as selected.
|
||||
final String? openId;
|
||||
final ValueChanged<String> onOpen;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final l10n = context.l10n;
|
||||
final theme = Theme.of(context);
|
||||
final playlists = ref.watch(desktopSidebarPlaylistsProvider);
|
||||
Widget row(String id, IconData icon, String label) => _RailLinkRow(
|
||||
key: ValueKey('desktop-rail-link:$id'),
|
||||
icon: icon,
|
||||
label: label,
|
||||
selected: id == openId,
|
||||
onTap: () => onOpen(id),
|
||||
);
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
// The heading starts at the destination icons.
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(
|
||||
_RailDestination._inset + 16,
|
||||
24,
|
||||
_RailDestination._inset,
|
||||
8,
|
||||
),
|
||||
child: Semantics(
|
||||
header: true,
|
||||
child: Text(
|
||||
l10n.searchPlaylists,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: theme.textTheme.titleSmall?.copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
row(
|
||||
DesktopSidebarLink.allPlaylistsId,
|
||||
Icons.queue_music,
|
||||
l10n.desktopAllPlaylists,
|
||||
),
|
||||
for (final playlist in playlists)
|
||||
row(
|
||||
DesktopSidebarLink.playlistId(playlist.id),
|
||||
Icons.playlist_play,
|
||||
playlist.name,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// A row in the expanded Material rail's Playlists section: the icon in line
|
||||
/// with the destination icons, a stadium hover layer and the selected
|
||||
/// destination's fill.
|
||||
class _RailLinkRow extends StatelessWidget {
|
||||
const _RailLinkRow({
|
||||
super.key,
|
||||
required this.icon,
|
||||
required this.label,
|
||||
required this.selected,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
final IconData icon;
|
||||
final String label;
|
||||
final bool selected;
|
||||
final VoidCallback onTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final colorScheme = theme.colorScheme;
|
||||
final foreground = selected
|
||||
? colorScheme.onSecondaryContainer
|
||||
: colorScheme.onSurfaceVariant;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: _RailDestination._inset),
|
||||
// Long playlist names are cut, so the tooltip shows them whole.
|
||||
child: Tooltip(
|
||||
message: label,
|
||||
waitDuration: const Duration(milliseconds: 800),
|
||||
excludeFromSemantics: true,
|
||||
child: Semantics(
|
||||
button: true,
|
||||
selected: selected,
|
||||
label: label,
|
||||
excludeSemantics: true,
|
||||
child: Material(
|
||||
color: selected ? colorScheme.secondaryContainer : null,
|
||||
type: selected ? MaterialType.canvas : MaterialType.transparency,
|
||||
shape: const StadiumBorder(),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: InkWell(
|
||||
onTap: onTap,
|
||||
hoverColor: foreground.withValues(alpha: 0.08),
|
||||
child: SizedBox(
|
||||
height: 44,
|
||||
child: Row(
|
||||
children: [
|
||||
const SizedBox(width: 16),
|
||||
AppIcon(icon, size: 24, color: foreground),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
label,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: theme.textTheme.labelLarge?.copyWith(
|
||||
color: foreground,
|
||||
fontWeight: selected
|
||||
? FontWeight.w700
|
||||
: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// One Material rail destination at [expansion] (0 collapsed, 1 expanded).
|
||||
///
|
||||
/// Collapsed, a 56x32 indicator holds the icon with the label below it.
|
||||
/// Expanded, a 56dp pill hugs the icon and the label beside it, as M3
|
||||
/// Expressive specifies. In between the pill grows from one shape to the
|
||||
/// other around a fixed icon, and the labels cross-fade, so collapsing and
|
||||
/// expanding never jump. Only the indicator (with the label below it while
|
||||
/// collapsed) takes clicks and hover.
|
||||
/// Collapsed, a 56x32 indicator holds the icon alone, named by a tooltip;
|
||||
/// a desktop rail of three or four destinations reads better without
|
||||
/// labels under the icons. Expanded, a 56dp pill spans the rail with the
|
||||
/// label beside the icon, as wide as the Playlists rows below (the owner's
|
||||
/// call over M3 Expressive's pill that hugs its label). In between the pill
|
||||
/// grows from one shape to the other around a fixed icon and the label fades
|
||||
/// in, so collapsing and expanding never jump. Only the indicator (the whole
|
||||
/// 56dp square while collapsed) takes clicks and hover.
|
||||
class _RailDestination extends StatefulWidget {
|
||||
const _RailDestination({
|
||||
super.key,
|
||||
@@ -635,33 +853,24 @@ class _RailDestinationState extends State<_RailDestination> {
|
||||
final expandedStyle = textTheme.labelLarge!.copyWith(
|
||||
fontWeight: selected ? FontWeight.w700 : FontWeight.w500,
|
||||
);
|
||||
final collapsedStyle = textTheme.labelMedium!.copyWith(
|
||||
fontWeight: selected ? FontWeight.w700 : FontWeight.w500,
|
||||
);
|
||||
// The expanded pill hugs its label, so measure it.
|
||||
final labelWidth = (TextPainter(
|
||||
text: TextSpan(text: destination.label, style: expandedStyle),
|
||||
textDirection: Directionality.of(context),
|
||||
textScaler: MediaQuery.textScalerOf(context),
|
||||
maxLines: 1,
|
||||
)..layout()).width;
|
||||
final maxPillWidth = desktopSidebarWidth - inset * 2;
|
||||
final expandedPillWidth = (16 + 24 + 8 + labelWidth + 16).clamp(
|
||||
56.0,
|
||||
maxPillWidth,
|
||||
);
|
||||
// The expanded pill spans the rail like the Playlists rows below, so
|
||||
// every fill and hover lines up at both edges.
|
||||
const expandedPillWidth = desktopSidebarWidth - inset * 2;
|
||||
|
||||
final height = lerpDouble(64, 56, t)!;
|
||||
const height = 56.0;
|
||||
final pill = Rect.fromLTWH(
|
||||
inset,
|
||||
lerpDouble(4, 0, t)!,
|
||||
lerpDouble(12, 0, t)!,
|
||||
lerpDouble(56, expandedPillWidth, t)!,
|
||||
lerpDouble(32, 56, t)!,
|
||||
);
|
||||
// Collapsed, the label under the indicator belongs to the target too.
|
||||
final target = Rect.lerp(Rect.fromLTWH(inset - 8, 0, 72, 64), pill, t)!;
|
||||
// Collapsed, the whole square around the indicator takes the click.
|
||||
final target = Rect.lerp(
|
||||
const Rect.fromLTWH(inset, 0, 56, height),
|
||||
pill,
|
||||
t,
|
||||
)!;
|
||||
final iconTop = pill.top + (pill.height - 24) / 2;
|
||||
final collapsedLabel = (1 - t * 2).clamp(0.0, 1.0);
|
||||
final expandedLabel = (t * 2 - 1).clamp(0.0, 1.0);
|
||||
|
||||
final foreground = selected
|
||||
@@ -683,6 +892,7 @@ class _RailDestinationState extends State<_RailDestination> {
|
||||
container: true,
|
||||
button: true,
|
||||
selected: selected,
|
||||
label: destination.label,
|
||||
child: SizedBox(
|
||||
height: height,
|
||||
child: Stack(
|
||||
@@ -733,26 +943,6 @@ class _RailDestinationState extends State<_RailDestination> {
|
||||
),
|
||||
),
|
||||
),
|
||||
if (collapsedLabel > 0)
|
||||
PositionedDirectional(
|
||||
start: 0,
|
||||
width: desktopCollapsedRailWidth,
|
||||
top: 40,
|
||||
child: Opacity(
|
||||
opacity: collapsedLabel,
|
||||
child: Text(
|
||||
destination.label,
|
||||
textAlign: TextAlign.center,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: collapsedStyle.copyWith(
|
||||
color: selected
|
||||
? colorScheme.onSurface
|
||||
: colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (expandedLabel > 0)
|
||||
PositionedDirectional(
|
||||
// Slides in from under the icon as it fades in.
|
||||
@@ -764,25 +954,36 @@ class _RailDestinationState extends State<_RailDestination> {
|
||||
opacity: expandedLabel,
|
||||
child: Align(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
child: Text(
|
||||
destination.label,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: expandedStyle.copyWith(color: foreground),
|
||||
// The destination's semantics already carry the label.
|
||||
child: ExcludeSemantics(
|
||||
child: Text(
|
||||
destination.label,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: expandedStyle.copyWith(color: foreground),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned.fromRect(
|
||||
rect: target,
|
||||
child: InkWell(
|
||||
onTap: widget.onTap,
|
||||
customBorder: const StadiumBorder(),
|
||||
overlayColor: const WidgetStatePropertyAll(Colors.transparent),
|
||||
splashFactory: NoSplash.splashFactory,
|
||||
onHover: (value) => setState(() => _hovered = value),
|
||||
onFocusChange: (value) => setState(() => _focused = value),
|
||||
onHighlightChanged: (value) => setState(() => _pressed = value),
|
||||
// Names the icon while the label is hidden.
|
||||
child: Tooltip(
|
||||
message: expandedLabel > 0 ? '' : destination.label,
|
||||
excludeFromSemantics: true,
|
||||
child: InkWell(
|
||||
onTap: widget.onTap,
|
||||
customBorder: const StadiumBorder(),
|
||||
overlayColor: const WidgetStatePropertyAll(
|
||||
Colors.transparent,
|
||||
),
|
||||
splashFactory: NoSplash.splashFactory,
|
||||
onHover: (value) => setState(() => _hovered = value),
|
||||
onFocusChange: (value) => setState(() => _focused = value),
|
||||
onHighlightChanged: (value) =>
|
||||
setState(() => _pressed = value),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -128,7 +128,7 @@ class _DesktopShortcutsState extends ConsumerState<DesktopShortcuts> {
|
||||
case DesktopCommand.upNext:
|
||||
toggleDesktopInspector(DesktopInspectorPanel.upNext);
|
||||
case DesktopCommand.toggleSidebar:
|
||||
desktopSidebarCollapsed.value = !desktopSidebarCollapsed.value;
|
||||
toggleDesktopSidebar();
|
||||
case DesktopCommand.refresh:
|
||||
AppRefreshIndicator.refreshVisible();
|
||||
case DesktopCommand.miniPlayer:
|
||||
|
||||
+158
-16
@@ -28,6 +28,7 @@ import 'package:mornye/widgets/desktop/desktop_window.dart';
|
||||
import 'package:mornye/widgets/expressive_navigation_bar.dart';
|
||||
import 'package:mornye/widgets/mini_player.dart';
|
||||
import 'package:mornye/widgets/mornye_bottom_bar.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class _FakeController implements MusicPlayerController {
|
||||
final calls = <String>[];
|
||||
@@ -90,6 +91,8 @@ void main() {
|
||||
late List<ShellTab> selections;
|
||||
|
||||
setUp(() {
|
||||
// The rail's menu button saves its state.
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
debugDesktopPlatformOverride = true;
|
||||
debugDesktopTitleBarInContentOverride = false;
|
||||
desktopSidebarCollapsed.value = false;
|
||||
@@ -130,6 +133,7 @@ void main() {
|
||||
WidgetTester tester, {
|
||||
required bool mornye,
|
||||
required double width,
|
||||
ShellTab selected = ShellTab.home,
|
||||
MediaItem? item = _track,
|
||||
List<DesktopSidebarLink> libraryLinks = const [],
|
||||
ValueChanged<String>? onOpenLibraryLink,
|
||||
@@ -152,7 +156,7 @@ void main() {
|
||||
home: Scaffold(
|
||||
body: DesktopShellLayout(
|
||||
destinations: _destinations(mornye: mornye),
|
||||
selected: ShellTab.home,
|
||||
selected: selected,
|
||||
onSelected: selections.add,
|
||||
libraryLinks: libraryLinks,
|
||||
onOpenLibraryLink: onOpenLibraryLink,
|
||||
@@ -262,6 +266,23 @@ void main() {
|
||||
expect(find.byType(DesktopDownloadsButton), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('the sidebar shortcut remembers the rail state', (
|
||||
tester,
|
||||
) async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
restoreDesktopSidebar(prefs);
|
||||
// Wide windows open with the rail expanded.
|
||||
expect(desktopSidebarCollapsed.value, isFalse);
|
||||
|
||||
toggleDesktopSidebar();
|
||||
await tester.pump();
|
||||
expect(desktopSidebarCollapsed.value, isTrue);
|
||||
desktopSidebarCollapsed.value = false;
|
||||
restoreDesktopSidebar(prefs);
|
||||
expect(desktopSidebarCollapsed.value, isTrue);
|
||||
});
|
||||
|
||||
testWidgets('expanded rail keeps a gap between indicators', (tester) async {
|
||||
await pumpShell(tester, mornye: false, width: 1400);
|
||||
|
||||
@@ -271,47 +292,168 @@ void main() {
|
||||
expect(library.center.dy - home.center.dy, closeTo(56 + 8, 0.5));
|
||||
});
|
||||
|
||||
testWidgets('rail starts collapsed with no menu button', (tester) async {
|
||||
testWidgets('collapsed rail shows icons alone and its menu expands it', (
|
||||
tester,
|
||||
) async {
|
||||
desktopSidebarCollapsed.value = true;
|
||||
await pumpShell(tester, mornye: false, width: 1400);
|
||||
double railWidth() =>
|
||||
tester.getSize(find.byType(DesktopNavigationRail)).width;
|
||||
expect(railWidth(), closeTo(desktopCollapsedRailWidth, 0.5));
|
||||
for (final icon in [Icons.menu, Icons.menu_open]) {
|
||||
expect(
|
||||
find.byWidgetPredicate((w) => w is AppIcon && w.icon == icon),
|
||||
findsNothing,
|
||||
);
|
||||
}
|
||||
Finder menuIcon(IconData icon) =>
|
||||
find.byWidgetPredicate((w) => w is AppIcon && w.icon == icon);
|
||||
expect(menuIcon(Icons.menu), findsOneWidget);
|
||||
// The menu button sits over the destination icons.
|
||||
expect(
|
||||
tester.getCenter(menuIcon(Icons.menu)).dx,
|
||||
closeTo(tester.getCenter(find.byTooltip('library')).dx, 0.5),
|
||||
);
|
||||
// No labels under the icons: tooltips and semantics name them, and
|
||||
// the whole 56dp square around an icon takes the click.
|
||||
expect(find.text('library'), findsNothing);
|
||||
expect(find.byTooltip('library'), findsOneWidget);
|
||||
final semantics = tester.ensureSemantics();
|
||||
await tester.pump();
|
||||
expect(
|
||||
tester
|
||||
.getSemantics(find.byKey(const ValueKey('desktop-rail:library')))
|
||||
.label,
|
||||
// The label, then the badge count.
|
||||
'library\n2',
|
||||
);
|
||||
semantics.dispose();
|
||||
final library = tester.getRect(find.byTooltip('library'));
|
||||
expect(library.size, const Size(56, 56));
|
||||
await tester.tapAt(library.topLeft + const Offset(4, 4));
|
||||
expect(selections, [ShellTab.library]);
|
||||
|
||||
// The sidebar shortcut expands it; halfway, the rail is between its
|
||||
// widths with one label showing.
|
||||
desktopSidebarCollapsed.value = false;
|
||||
// The menu button expands it; halfway, the rail is between its widths
|
||||
// with one label showing.
|
||||
await tester.tap(find.byKey(const ValueKey('desktop-rail-menu')));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 120));
|
||||
expect(desktopSidebarCollapsed.value, isFalse);
|
||||
expect(railWidth(), greaterThan(desktopCollapsedRailWidth));
|
||||
expect(railWidth(), lessThan(desktopSidebarWidth));
|
||||
expect(find.text('library'), findsOneWidget);
|
||||
await tester.pumpAndSettle();
|
||||
expect(railWidth(), closeTo(desktopSidebarWidth, 0.5));
|
||||
expect(menuIcon(Icons.menu_open), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('expanded rail pills hug their labels and take the clicks', (
|
||||
testWidgets('narrow windows hide the rail menu button', (tester) async {
|
||||
await pumpShell(tester, mornye: false, width: 900);
|
||||
|
||||
expect(find.byKey(const ValueKey('desktop-rail-menu')), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('expanded rail lists the playlists under the destinations', (
|
||||
tester,
|
||||
) async {
|
||||
final opened = <String>[];
|
||||
await pumpShell(
|
||||
tester,
|
||||
mornye: false,
|
||||
width: 1400,
|
||||
onOpenLibraryLink: opened.add,
|
||||
);
|
||||
|
||||
final settings = tester.getRect(find.text('settings'));
|
||||
final allPlaylists = tester.getRect(find.text('All Playlists'));
|
||||
final playlist = tester.getRect(find.text('Road trip'));
|
||||
expect(find.text('Playlists'), findsOneWidget);
|
||||
expect(
|
||||
allPlaylists.top,
|
||||
greaterThan(tester.getRect(find.text('repository')).bottom),
|
||||
);
|
||||
expect(playlist.top, greaterThan(allPlaylists.bottom));
|
||||
expect(settings.top, greaterThan(playlist.bottom));
|
||||
// Rows start their icons at the destination icons and fill the rail.
|
||||
final row = tester.getRect(
|
||||
find.byKey(const ValueKey('desktop-rail-link:playlist:mix')),
|
||||
);
|
||||
expect(row.height, 44);
|
||||
expect(
|
||||
tester
|
||||
.getRect(find.byKey(const ValueKey('desktop-rail-link:playlists')))
|
||||
.width,
|
||||
row.width,
|
||||
);
|
||||
|
||||
await tester.tap(find.text('Road trip'));
|
||||
await tester.tap(find.text('All Playlists'));
|
||||
expect(opened, ['playlist:mix', 'playlists']);
|
||||
|
||||
// An open playlist takes the selection from Library.
|
||||
await pumpShell(
|
||||
tester,
|
||||
mornye: false,
|
||||
width: 1400,
|
||||
selected: ShellTab.library,
|
||||
onOpenLibraryLink: opened.add,
|
||||
);
|
||||
bool selectedFill(Finder finder) =>
|
||||
tester
|
||||
.widget<Material>(
|
||||
find.descendant(of: finder, matching: find.byType(Material)),
|
||||
)
|
||||
.type ==
|
||||
MaterialType.canvas;
|
||||
final mix = find.byKey(const ValueKey('desktop-rail-link:playlist:mix'));
|
||||
expect(selectedFill(mix), isFalse);
|
||||
desktopSidebarLink.value = 'playlist:mix';
|
||||
await tester.pumpAndSettle();
|
||||
expect(selectedFill(mix), isTrue);
|
||||
|
||||
// Collapsed, only the destinations show.
|
||||
desktopSidebarCollapsed.value = true;
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Playlists'), findsNothing);
|
||||
expect(find.text('Road trip'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('Library leaves an open playlist for the Library root', (
|
||||
tester,
|
||||
) async {
|
||||
final opened = <String>[];
|
||||
await pumpShell(
|
||||
tester,
|
||||
mornye: false,
|
||||
width: 1400,
|
||||
onOpenLibraryLink: opened.add,
|
||||
);
|
||||
|
||||
// Nothing open: Library switches tabs.
|
||||
await tester.tap(find.text('library'));
|
||||
expect(selections, [ShellTab.library]);
|
||||
expect(opened, isEmpty);
|
||||
|
||||
// A playlist left open from another tab: Library returns to the root
|
||||
// instead of showing the playlist again.
|
||||
desktopSidebarLink.value = DesktopSidebarLink.allPlaylistsId;
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('library'));
|
||||
expect(opened, [DesktopSidebarLink.libraryRootId]);
|
||||
expect(selections, [ShellTab.library]);
|
||||
});
|
||||
|
||||
testWidgets('expanded rail pills span the rail and take the clicks', (
|
||||
tester,
|
||||
) async {
|
||||
await pumpShell(tester, mornye: false, width: 1400);
|
||||
|
||||
final library = tester.getRect(find.text('library'));
|
||||
final settings = tester.getRect(find.text('settings'));
|
||||
// Beside a pill, inside the rail: nothing happens.
|
||||
// In the rail's margin beside a pill: nothing happens.
|
||||
final rail = tester.getRect(find.byType(DesktopNavigationRail));
|
||||
await tester.tapAt(Offset(rail.right - 12, library.center.dy));
|
||||
await tester.tapAt(Offset(rail.right - 12, settings.center.dy));
|
||||
expect(selections, isEmpty);
|
||||
|
||||
// On the pill, just past the label: selects.
|
||||
await tester.tapAt(Offset(library.right + 8, library.center.dy));
|
||||
await tester.tapAt(Offset(settings.right + 8, settings.center.dy));
|
||||
// Near the pill's far end, past any label: selects, as the Playlists
|
||||
// rows do.
|
||||
await tester.tapAt(Offset(rail.right - 28, library.center.dy));
|
||||
await tester.tapAt(Offset(rail.right - 28, settings.center.dy));
|
||||
expect(selections, [ShellTab.library, ShellTab.settings]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user