Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
ethan
/
appframe
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit a242c47d
authored
2025-12-18 09:07:43 +0800
by
tanghuan
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
监测ios白屏问题
1 parent
35706230
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
12 deletions
lib/bloc/web_cubit.dart
lib/ui/pages/web_page.dart
lib/bloc/web_cubit.dart
View file @
a242c47
...
...
@@ -63,6 +63,9 @@ class WebState extends Equatable {
final
String
h5Version
;
/// 用于测试监测问题
final
String
testMsg
;
const
WebState
({
this
.
selectedIndex
=
0
,
this
.
loaded
=
false
,
...
...
@@ -87,6 +90,7 @@ class WebState extends Equatable {
this
.
chooseVideoCmdFlag
=
false
,
this
.
chooseVideoCmdMessage
=
''
,
this
.
h5Version
=
''
,
this
.
testMsg
=
''
,
});
WebState
copyWith
({
...
...
@@ -114,6 +118,7 @@ class WebState extends Equatable {
bool
?
chooseVideoCmdFlag
,
String
?
chooseVideoCmdMessage
,
String
?
h5Version
,
String
?
testMsg
,
})
{
return
WebState
(
selectedIndex:
selectedIndex
??
this
.
selectedIndex
,
...
...
@@ -139,6 +144,7 @@ class WebState extends Equatable {
chooseVideoCmdFlag:
chooseVideoCmdFlag
??
this
.
chooseVideoCmdFlag
,
chooseVideoCmdMessage:
chooseVideoCmdMessage
??
this
.
chooseVideoCmdMessage
,
h5Version:
h5Version
??
this
.
h5Version
,
testMsg:
testMsg
??
this
.
testMsg
,
);
}
...
...
@@ -167,6 +173,7 @@ class WebState extends Equatable {
chooseVideoCmdFlag
,
chooseVideoCmdMessage
,
h5Version
,
testMsg
,
];
}
...
...
@@ -1045,6 +1052,36 @@ class WebCubit extends Cubit<WebState> with WidgetsBindingObserver {
_sendResponse
(
resp
);
}
Future
<
void
>
_checkLocalServerStatus
()
async
{
var
localServerService
=
getIt
.
get
<
LocalServerService
>();
var
result
=
await
localServerService
.
checkServerHealth
();
if
(!
result
)
{
try
{
// 安全起见,执行一次关闭旧的server,
_server
?.
close
();
}
catch
(
e
)
{
print
(
'SocketException:
$e
'
);
}
emit
(
state
.
copyWith
(
testMsg:
'A
${DateTime.now()}
'
));
_server
=
await
localServerService
.
restartLocalServer
();
}
}
Future
<
void
>
_checkWebViewStatus
()
async
{
try
{
// 尝试获取页面标题来验证 WebView 是否响应
final
title
=
await
controller
.
runJavaScriptReturningResult
(
'document.title'
);
if
(
title
.
toString
().
isEmpty
)
{
emit
(
state
.
copyWith
(
testMsg:
'C
${DateTime.now()}
'
));
_loadHtml
();
}
}
catch
(
e
)
{
// JavaScript 执行失败,可能 WebView 已失效
emit
(
state
.
copyWith
(
testMsg:
'B
${DateTime.now()}
'
));
_loadHtml
();
}
}
///
/// iOS:用于标识是初次启动,还是从后台恢复
///
...
...
@@ -1057,17 +1094,10 @@ class WebCubit extends Cubit<WebState> with WidgetsBindingObserver {
if
(
lifecycleState
==
AppLifecycleState
.
resumed
)
{
if
(
_hasBeenResumed
)
{
// 代表从后台恢复
var
localServerService
=
getIt
.
get
<
LocalServerService
>();
var
result
=
await
localServerService
.
checkServerHealth
();
if
(!
result
)
{
try
{
// 安全起见,执行一次关闭旧的server,
_server
?.
close
();
}
catch
(
e
)
{
print
(
'SocketException:
$e
'
);
}
_server
=
await
localServerService
.
restartLocalServer
();
}
// 1 检测本机Http服务
_checkLocalServerStatus
();
// 2 检测WebView状态
_checkWebViewStatus
();
}
else
{
// 代表初次
_hasBeenResumed
=
true
;
...
...
lib/ui/pages/web_page.dart
View file @
a242c47
...
...
@@ -138,7 +138,7 @@ class WebPage extends StatelessWidget {
AppBar
_buildAppBar
(
BuildContext
ctx
,
WebState
state
)
{
return
AppBar
(
title:
Text
(
state
.
title
,
style:
TextStyle
(
color:
Color
(
state
.
titleColor
),
fontSize:
18
)),
title:
Text
(
state
.
title
+
state
.
testMsg
,
style:
TextStyle
(
color:
Color
(
state
.
titleColor
),
fontSize:
18
)),
centerTitle:
true
,
automaticallyImplyLeading:
false
,
backgroundColor:
Color
(
state
.
bgColor
),
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
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 post a comment