Files
jiu/client/lib/main.dart
T
wangjia cc687ae0c3 feat(client): 登录模块对接后端 API
- auth_state: 增加 refreshToken 字段 + flutter_secure_storage 持久化
- api_client: 增加 401 自动 refresh + retry 拦截器
- auth_repository: 封装 POST /api/v1/auth/login 调用,错误信息本地化
- login_screen: 增加门店编号字段,调真实 API,行内错误展示
- main: 启动时 restore 持久化登录态,避免每次重启都要重新登录
- 修复 app_shell: hotelName → hotelNo
- 修复 widget_test: 移除失效的占位测试

测试账号:门店编号 H001 / 用户名 admin / 密码 password123

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-04 23:18:57 +08:00

70 lines
1.6 KiB
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() {
runApp(const ProviderScope(child: JiuApp()));
}
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,
);
}
}