d717fb3735
API 对接: - 入库/出库/库存/财务/往来单位/基础数据全部对接后端 REST API - 新增 repositories、providers、models 层,统一分层架构 - auth 从 flutter_secure_storage 迁移到 shared_preferences 登陆跳转修复: - 将 _RouterNotifier 提取为独立 Riverpod provider,appRouterProvider 使用 ref.read 避免依赖链导致 router 重建后跳回 /login - redirect 函数新增 initialized 守卫,防止 auth 未恢复时误重定向 - 添加调试日志(Router/Auth/ApiClient)定位 401 触发的 logout 链路 退出菜单 UI: - 去掉 ListTile,改用 Row + 自定义 padding,文字左对齐 - MouseRegion + AnimatedContainer 实现 hover 高亮(普通项蓝底/退出红底) - 菜单圆角 6px,elevation 8,分割线高度 1px Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
86 lines
2.2 KiB
Dart
86 lines
2.2 KiB
Dart
import 'dart:async';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'core/auth/auth_state.dart';
|
|
import 'core/router/app_router.dart';
|
|
import 'core/theme/app_theme.dart';
|
|
|
|
void main() {
|
|
FlutterError.onError = (details) {
|
|
FlutterError.presentError(details);
|
|
debugPrint('═══ FlutterError ════════════════════════════');
|
|
debugPrint(details.exceptionAsString());
|
|
debugPrint(details.stack.toString());
|
|
};
|
|
|
|
runZonedGuarded(
|
|
() => runApp(const ProviderScope(child: JiuApp())),
|
|
(error, stack) {
|
|
debugPrint('═══ Zone Error ═══════════════════════════════');
|
|
debugPrint(error.toString());
|
|
debugPrint(stack.toString());
|
|
},
|
|
);
|
|
}
|
|
|
|
class JiuApp extends ConsumerWidget {
|
|
const JiuApp({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
return MaterialApp(
|
|
title: '酒库管理系统',
|
|
theme: AppTheme.light(),
|
|
debugShowCheckedModeBanner: false,
|
|
home: const _AppBootstrap(),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Restores persisted auth before handing off to the router.
|
|
class _AppBootstrap extends ConsumerStatefulWidget {
|
|
const _AppBootstrap();
|
|
|
|
@override
|
|
ConsumerState<_AppBootstrap> createState() => _AppBootstrapState();
|
|
}
|
|
|
|
class _AppBootstrapState extends ConsumerState<_AppBootstrap> {
|
|
bool _ready = false;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_init();
|
|
}
|
|
|
|
Future<void> _init() async {
|
|
await ref.read(authStateProvider.notifier).restore();
|
|
if (mounted) setState(() => _ready = true);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (!_ready) {
|
|
return const Scaffold(
|
|
body: Center(child: CircularProgressIndicator()),
|
|
);
|
|
}
|
|
return _RouterApp();
|
|
}
|
|
}
|
|
|
|
class _RouterApp extends ConsumerWidget {
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final router = ref.watch(appRouterProvider);
|
|
return MaterialApp.router(
|
|
title: '酒库管理系统',
|
|
theme: AppTheme.light(),
|
|
routerConfig: router,
|
|
debugShowCheckedModeBanner: false,
|
|
);
|
|
}
|
|
}
|