fix(client): 账号菜单改 showMenu 等宽触发器 + 向上弹(修菜单溢出盖内容)
上一版用 PopupMenuButton width:218 + offset:-12 反而把菜单外扩、右缘越过侧栏 盖住内容区。改为 GestureDetector + showMenu,菜单宽度 = 用户区实测宽度(自动与 侧栏内容等宽、绝不溢出),底部空间不足 showMenu 自动向上弹、不遮触发器。 加 user_menu_width_test:点开后断言菜单宽≈194、右缘≤218(弹出态回归)。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TSKEiHsvauyxYUW2itzUXX
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:jiu_client/core/auth/auth_state.dart';
|
||||
import 'package:jiu_client/core/theme/themes.dart';
|
||||
import 'package:jiu_client/models/shop.dart';
|
||||
import 'package:jiu_client/providers/shop_provider.dart';
|
||||
import 'package:jiu_client/providers/license_provider.dart';
|
||||
import 'package:jiu_client/providers/update_provider.dart';
|
||||
import 'package:jiu_client/providers/connectivity_provider.dart';
|
||||
import 'package:jiu_client/providers/session_heartbeat.dart';
|
||||
import 'package:jiu_client/screens/shell/app_shell.dart';
|
||||
import 'package:jiu_client/widgets/app_status_bar.dart';
|
||||
|
||||
/// 弹出态回归:侧栏底部「账号菜单」弹出后宽度 = 触发器宽(与侧栏内容等宽),
|
||||
/// 且不溢出侧栏右缘(218)——修复「菜单比按钮宽、盖住内容区」。
|
||||
|
||||
class _FakeAuth extends AuthNotifier {
|
||||
_FakeAuth() {
|
||||
state = const AuthState(
|
||||
user: AuthUser(
|
||||
accessToken: 't', refreshToken: 'r', id: 1, username: 'wang',
|
||||
realName: '王经理', shopNo: 'DSJH-001', shopId: 1, role: 'admin'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _FakeUpdate extends UpdateNotifier {
|
||||
@override
|
||||
Future<AppUpdateInfo?> build() async => null;
|
||||
}
|
||||
|
||||
class _FakeLicense extends LicenseNotifier {
|
||||
@override
|
||||
Future<LicenseInfo?> build() async => null;
|
||||
}
|
||||
|
||||
const _shop = ShopInfo(
|
||||
id: 1, code: 'DSJH-001', name: '鼎晟酒行',
|
||||
address: '浙江省杭州市', phone: '0571-88886666', managerName: '王经理');
|
||||
|
||||
GoRouter _router() => GoRouter(
|
||||
initialLocation: '/inventory',
|
||||
routes: [
|
||||
StatefulShellRoute.indexedStack(
|
||||
builder: (ctx, state, shell) => AppShell(navigationShell: shell),
|
||||
branches: [
|
||||
for (final p in const [
|
||||
'/stock-in', '/stock-out', '/inventory', '/finance',
|
||||
'/partners', '/products', '/devices', '/settings', '/about'
|
||||
])
|
||||
StatefulShellBranch(routes: [
|
||||
GoRoute(path: p, builder: (_, __) => const SizedBox.expand()),
|
||||
]),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
AppStatusBar.ticking = false;
|
||||
|
||||
testWidgets('账号菜单宽度=触发器宽,不溢出侧栏(218)', (tester) async {
|
||||
tester.view.physicalSize = const Size(2560, 1800);
|
||||
tester.view.devicePixelRatio = 2.0;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
|
||||
await tester.pumpWidget(ProviderScope(
|
||||
overrides: [
|
||||
authStateProvider.overrideWith((ref) => _FakeAuth()),
|
||||
shopInfoProvider.overrideWith((ref) => _shop),
|
||||
licenseProvider.overrideWith(() => _FakeLicense()),
|
||||
updateProvider.overrideWith(() => _FakeUpdate()),
|
||||
connectivityProvider
|
||||
.overrideWith((ref) => ConnectivityNotifier(skipInit: true)),
|
||||
sessionHeartbeatProvider.overrideWith((ref) => SessionHeartbeat(ref)),
|
||||
appVersionProvider.overrideWith((ref) => 'v1.0.72'),
|
||||
isReadonlyProvider.overrideWithValue(false),
|
||||
],
|
||||
child: MaterialApp.router(
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: buildTheme('a'),
|
||||
routerConfig: _router(),
|
||||
),
|
||||
));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// 点开账号菜单(side-user 含「· 管理员」)
|
||||
await tester.tap(find.textContaining('管理员'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('个人设置'), findsOneWidget);
|
||||
expect(find.text('退出登录'), findsOneWidget);
|
||||
|
||||
// 菜单项填满菜单宽:宽 ≈ 侧栏内容宽(194),右缘不超过侧栏右缘(218)
|
||||
final itemRect = tester.getRect(find.byType(PopupMenuItem<String>).first);
|
||||
expect(itemRect.width, inInclusiveRange(180, 200),
|
||||
reason: '菜单应与触发器等宽(~194),不应外扩到 218 而溢出');
|
||||
expect(itemRect.right, lessThanOrEqualTo(219),
|
||||
reason: '菜单右缘不得越过侧栏右缘(218)盖住内容区');
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user