37112d6599
- 替换 flutter_secure_storage 为 shared_preferences,解决 macOS Keychain 签名报错 - 登录页门店编号/用户名支持历史下拉(最多5条,LRU 淘汰),使用 Overlay + CompositedTransformFollower 实现浮层 - logout 仅删除 auth token,保留登录历史 - AppShell 时钟抽为独立 _ClockWidget,避免每秒 setState 导致 TabBarView 叠影 - ShellRoute 子路由改用 NoTransitionPage,消除切换页面时的过渡动画叠影 - 新增 auth_state_test、auth_repository_test、login_screen_test 共 14 个单元/Widget 测试 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
74 lines
2.7 KiB
Dart
74 lines
2.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import '../../screens/auth/login_screen.dart';
|
|
import '../../screens/shell/app_shell.dart';
|
|
import '../../screens/stock_in/stock_in_list_screen.dart';
|
|
import '../../screens/stock_in/stock_in_form_screen.dart';
|
|
import '../../screens/stock_out/stock_out_list_screen.dart';
|
|
import '../../screens/inventory/inventory_list_screen.dart';
|
|
import '../../screens/inventory/inventory_check_screen.dart';
|
|
import '../../screens/partners/partners_screen.dart';
|
|
import '../../screens/finance/finance_screen.dart';
|
|
import '../../screens/products/products_screen.dart';
|
|
import '../../screens/settings/settings_screen.dart';
|
|
import '../auth/auth_state.dart';
|
|
|
|
Page<void> _noTransition(Widget child) =>
|
|
NoTransitionPage<void>(child: child);
|
|
|
|
final appRouterProvider = Provider<GoRouter>((ref) {
|
|
final authState = ref.watch(authStateProvider);
|
|
|
|
return GoRouter(
|
|
initialLocation: '/login',
|
|
redirect: (context, state) {
|
|
final isLoggedIn = authState.isLoggedIn;
|
|
final isLoginRoute = state.matchedLocation == '/login';
|
|
if (!isLoggedIn && !isLoginRoute) return '/login';
|
|
if (isLoggedIn && isLoginRoute) return '/stock-in';
|
|
return null;
|
|
},
|
|
routes: [
|
|
GoRoute(
|
|
path: '/login',
|
|
builder: (context, state) => const LoginScreen(),
|
|
),
|
|
ShellRoute(
|
|
builder: (context, state, child) => AppShell(child: child),
|
|
routes: [
|
|
GoRoute(
|
|
path: '/stock-in',
|
|
pageBuilder: (_, __) => _noTransition(const StockInListScreen())),
|
|
GoRoute(
|
|
path: '/stock-in/new',
|
|
pageBuilder: (_, __) => _noTransition(const StockInFormScreen())),
|
|
GoRoute(
|
|
path: '/stock-out',
|
|
pageBuilder: (_, __) => _noTransition(const StockOutListScreen())),
|
|
GoRoute(
|
|
path: '/inventory',
|
|
pageBuilder: (_, __) =>
|
|
_noTransition(const InventoryListScreen())),
|
|
GoRoute(
|
|
path: '/inventory/check',
|
|
pageBuilder: (_, __) =>
|
|
_noTransition(const InventoryCheckScreen())),
|
|
GoRoute(
|
|
path: '/partners',
|
|
pageBuilder: (_, __) => _noTransition(const PartnersScreen())),
|
|
GoRoute(
|
|
path: '/finance',
|
|
pageBuilder: (_, __) => _noTransition(const FinanceScreen())),
|
|
GoRoute(
|
|
path: '/products',
|
|
pageBuilder: (_, __) => _noTransition(const ProductsScreen())),
|
|
GoRoute(
|
|
path: '/settings',
|
|
pageBuilder: (_, __) => _noTransition(const SettingsScreen())),
|
|
],
|
|
),
|
|
],
|
|
);
|
|
});
|