Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
laki_icu_app
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张宏
laki_icu_app
Commits
b5abe691
Commit
b5abe691
authored
Jun 26, 2026
by
张宏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
777777777777
parent
95cd69f5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
33 deletions
+16
-33
main.dart
lib/main.dart
+16
-33
No files found.
lib/main.dart
View file @
b5abe691
...
...
@@ -135,28 +135,11 @@ class _MyAppState extends State<MyApp> {
}
_endInitializing
();
}
else
{
// 无 Token,执行静默登录
await
_performSilentLogin
();
}
}
/// 静默登录核心逻辑:使用预设账号自动登录
Future
<
void
>
_silentLogin
()
async
{
try
{
await
_authService
.
login
(
'13800000001'
,
'111111'
);
// 登录成功,获取用户信息
_authBloc
.
add
(
const
AuthFetchUserInfo
());
}
catch
(
e
)
{
// 静默登录失败,不做任何处理
// 无 Token,直接结束初始化
_endInitializing
();
}
}
/// 启动时的静默登录,登录完成后结束初始化状态
Future
<
void
>
_performSilentLogin
()
async
{
await
_silentLogin
();
_endInitializing
();
}
void
_endInitializing
()
{
if
(
mounted
)
{
setState
(()
{
...
...
@@ -207,20 +190,20 @@ class _MyAppState extends State<MyApp> {
],
child:
MultiBlocListener
(
listeners:
[
// AuthBloc 监听器 - 处理登录/Token 过期/登出
BlocListener
<
AuthBloc
,
AuthState
>(
listener:
(
context
,
state
)
{
if
(
state
is
AuthSuccess
)
{
_appRouter
.
replaceAll
([
const
DefaultLayoutRoute
()]);
}
if
(
state
is
AuthTokenExpired
)
{
_silentLogin
();
}
if
(
state
is
AuthLoggedOut
)
{
_silentLogin
();
}
},
),
//
//
AuthBloc 监听器 - 处理登录/Token 过期/登出
//
BlocListener<AuthBloc, AuthState>(
//
listener: (context, state) {
//
if (state is AuthSuccess) {
//
_appRouter.replaceAll([const DefaultLayoutRoute()]);
//
}
//
if (state is AuthTokenExpired) {
//
_silentLogin();
//
}
//
if (state is AuthLoggedOut) {
//
_silentLogin();
//
}
//
},
//
),
// 未来在这里添加其他 Bloc 的监听器:
// BlocListener<UserBloc, UserState>(listener: ...),
// BlocListener<SettingsBloc, SettingsState>(listener: ...),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment