style: move collapsed sidebar expand control to top

This commit is contained in:
Haitao Pan 2026-03-30 13:26:51 +08:00
parent de4dca4cad
commit cc0580437d
2 changed files with 50 additions and 1 deletions

View File

@ -106,6 +106,13 @@ class SidebarNavigation extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const SizedBox(height: 4),
if (isCollapsed && showCollapseControl) ...[
SidebarHeader(
isCollapsed: true,
onTap: onExpandFromCollapsed,
),
const SizedBox(height: AppSpacing.xs),
],
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
@ -151,7 +158,7 @@ class SidebarNavigation extends StatelessWidget {
),
accountSelected:
currentSection == WorkspaceDestination.account,
showCollapseControl: showCollapseControl && isCollapsed,
showCollapseControl: false,
),
],
),
@ -189,6 +196,7 @@ class SidebarHeader extends StatelessWidget {
child: Align(
alignment: Alignment.centerRight,
child: InkWell(
key: const Key('sidebar-header-expand-button'),
borderRadius: BorderRadius.circular(AppRadius.button),
onTap: onTap,
child: Padding(padding: EdgeInsets.zero, child: content),

View File

@ -160,6 +160,47 @@ void main() {
);
});
testWidgets('SidebarNavigation shows collapsed expand button at the top', (
WidgetTester tester,
) async {
var expanded = 0;
await tester.pumpWidget(
MaterialApp(
theme: AppTheme.light(),
home: Scaffold(
body: SidebarNavigation(
currentSection: WorkspaceDestination.assistant,
sidebarState: AppSidebarState.collapsed,
appLanguage: AppLanguage.zh,
themeMode: ThemeMode.light,
onSectionChanged: (_) {},
onToggleLanguage: () {},
onCycleSidebarState: () {},
onExpandFromCollapsed: () => expanded++,
onOpenHome: () {},
onOpenAccount: () {},
onOpenThemeToggle: () {},
accountName: 'Tester',
accountSubtitle: 'Workspace',
onToggleAccountWorkspaceFollowed: () async {},
),
),
),
);
await tester.pumpAndSettle();
expect(find.byKey(const Key('sidebar-header-expand-button')), findsOneWidget);
expect(
find.byKey(const ValueKey<String>('sidebar-footer-collapse')),
findsNothing,
);
await tester.tap(find.byKey(const Key('sidebar-header-expand-button')));
await tester.pumpAndSettle();
expect(expanded, 1);
});
testWidgets('SidebarNavigation merges task controls into the global left bar', (
WidgetTester tester,
) async {