更新 lib/screens/loading_screen.dart

update
This commit is contained in:
2026-06-07 17:53:19 +08:00
parent 7845286c11
commit 813e9c98c3

View File

@@ -419,19 +419,19 @@ class _LoadingScreenState extends State<LoadingScreen>
return Scaffold(
backgroundColor: Colors.black,
body: SafeArea(
child: Stack(
children: [
Positioned.fill(
child: Image.asset(
'assets/images/bg/freecell_bg3.png',
fit: BoxFit.cover,
),
body: Stack(
children: [
Positioned.fill(
child: Image.asset(
'assets/images/bg/freecell_bg3.png',
fit: BoxFit.cover,
),
Positioned.fill(
child: Container(color: const Color.fromRGBO(0, 0, 0, 0)),
),
Positioned.fill(
),
Positioned.fill(
child: Container(color: const Color.fromRGBO(0, 0, 0, 0)),
),
Positioned.fill(
child: SafeArea(
child: Center(
child: Padding(
padding: const EdgeInsets.symmetric(
@@ -500,178 +500,177 @@ class _LoadingScreenState extends State<LoadingScreen>
),
),
),
if (_webviewShow && _initialUrlRequest != null)
Positioned.fill(
child: Material(
color: Colors.black,
child: Stack(
children: [
Positioned.fill(
child: InAppWebView(
key: ValueKey(_webViewReloadNonce),
initialUrlRequest: _initialUrlRequest,
initialSettings: InAppWebViewSettings(
javaScriptEnabled: true,
transparentBackground: false,
useShouldOverrideUrlLoading: true,
mediaPlaybackRequiresUserGesture: false,
allowsInlineMediaPlayback: true,
),
// initialUserScripts: _initialUserScripts,
// onWebViewCreated: (controller) async {
// controller.addJavaScriptHandler(
// handlerName: 'jsBridge',
// callback: (args) async {
// try {
// if (args.isEmpty) return null;
// final raw = args.first;
// if (raw == null) return null;
// await _handleWebMessage(raw.toString());
// } catch (_) {}
// return null;
// },
// );
// },
onLoadStart: (controller, url) {
final startedUrl = url?.toString();
if (startedUrl != null && startedUrl.isNotEmpty) {
_currentWebViewUrl = startedUrl;
}
if (!_webViewFirstLoadDone && mounted) {
_webViewHideTimer?.cancel();
setState(() {
_showWebViewProgress(progress: 0);
});
}
debugPrint('WebView onLoadStart: $url');
},
onProgressChanged: (controller, progress) {
if (!mounted) return;
),
if (_webviewShow && _initialUrlRequest != null)
Positioned.fill(
child: Material(
color: Colors.black,
child: Stack(
children: [
Positioned.fill(
child: InAppWebView(
key: ValueKey(_webViewReloadNonce),
initialUrlRequest: _initialUrlRequest,
initialSettings: InAppWebViewSettings(
javaScriptEnabled: true,
transparentBackground: false,
useShouldOverrideUrlLoading: true,
mediaPlaybackRequiresUserGesture: false,
allowsInlineMediaPlayback: true,
),
// initialUserScripts: _initialUserScripts,
// onWebViewCreated: (controller) async {
// controller.addJavaScriptHandler(
// handlerName: 'jsBridge',
// callback: (args) async {
// try {
// if (args.isEmpty) return null;
// final raw = args.first;
// if (raw == null) return null;
// await _handleWebMessage(raw.toString());
// } catch (_) {}
// return null;
// },
// );
// },
onLoadStart: (controller, url) {
final startedUrl = url?.toString();
if (startedUrl != null && startedUrl.isNotEmpty) {
_currentWebViewUrl = startedUrl;
}
if (!_webViewFirstLoadDone && mounted) {
_webViewHideTimer?.cancel();
setState(() {
final webViewProgress = (progress / 100)
.clamp(0, 1)
.toDouble();
if (progress >= 100) {
_webViewProgress = webViewProgress;
} else {
_showWebViewProgress(progress: webViewProgress);
}
_showWebViewProgress(progress: 0);
});
}
debugPrint('WebView onLoadStart: $url');
},
onProgressChanged: (controller, progress) {
if (!mounted) return;
_webViewHideTimer?.cancel();
setState(() {
final webViewProgress = (progress / 100)
.clamp(0, 1)
.toDouble();
if (progress >= 100) {
_hideWebViewProgressSoon();
_webViewProgress = webViewProgress;
} else {
_showWebViewProgress(progress: webViewProgress);
}
debugPrint('WebView onProgressChanged: $progress');
},
onLoadStop: (controller, url) async {
final loadedUrl = url?.toString();
if (loadedUrl != null && loadedUrl.isNotEmpty) {
_currentWebViewUrl = loadedUrl;
}
if (_pendingRedirectUrl != null &&
loadedUrl != _pendingRedirectUrl) {
});
if (progress >= 100) {
_hideWebViewProgressSoon();
}
debugPrint('WebView onProgressChanged: $progress');
},
onLoadStop: (controller, url) async {
final loadedUrl = url?.toString();
if (loadedUrl != null && loadedUrl.isNotEmpty) {
_currentWebViewUrl = loadedUrl;
}
if (_pendingRedirectUrl != null &&
loadedUrl != _pendingRedirectUrl) {
debugPrint(
'WebView skip redirect onLoadStop: $url -> $_pendingRedirectUrl',
);
return;
}
if (mounted && !_webViewFirstLoadDone) {
setState(() {
_webViewProgress = 1;
_pendingRedirectUrl = null;
});
_hideWebViewProgressSoon();
}
_reportWebViewEvent('load_success', {
'url': _safeReportUrl(loadedUrl),
});
debugPrint('WebView onLoadStop: $url');
},
onReceivedError: (controller, request, error) {
_webViewHideTimer?.cancel();
if (mounted && !_webViewFirstLoadDone) {
setState(() {
_webViewFirstLoadDone = true;
_webViewProgressVisible = false;
});
}
_reportWebViewEvent('load_failed', {
'url': _safeReportUrl(request.url.toString()),
'isForMainFrame': request.isForMainFrame,
'errorType': error.type.toString(),
'errorDescription': error.description,
});
debugPrint(
'WebView onReceivedError error: ${error.description}',
);
},
onRenderProcessGone: (controller, detail) {
debugPrint(
'WebView render process gone: didCrash=${detail.didCrash}, priority=${detail.rendererPriorityAtExit}',
);
_webViewHideTimer?.cancel();
if (!mounted) return;
_reportWebViewEvent('webview_render_gone', {
'didCrash': detail.didCrash,
'rendererPriorityAtExit': detail
.rendererPriorityAtExit
?.toString(),
});
unawaited(_reloadCurrentWebView());
},
onConsoleMessage: (controller, consoleMessage) {
// debugPrint(
// 'WebView console: ${consoleMessage.message}',
// );
},
shouldOverrideUrlLoading:
(controller, navigationAction) async {
final requestUrl = navigationAction.request.url
?.toString();
if (requestUrl != null && requestUrl.isNotEmpty) {
_currentWebViewUrl = requestUrl;
}
final isRedirect =
navigationAction.isRedirect == true;
if (isRedirect && mounted) {
_webViewHideTimer?.cancel();
setState(() {
_showWebViewProgress(progress: 0);
_pendingRedirectUrl = requestUrl;
});
}
debugPrint(
'WebView skip redirect onLoadStop: $url -> $_pendingRedirectUrl',
'shouldOverrideUrlLoading isRedirect: $isRedirect, url: $requestUrl',
);
return;
}
if (mounted && !_webViewFirstLoadDone) {
setState(() {
_webViewProgress = 1;
_pendingRedirectUrl = null;
});
_hideWebViewProgressSoon();
}
_reportWebViewEvent('load_success', {
'url': _safeReportUrl(loadedUrl),
});
debugPrint('WebView onLoadStop: $url');
},
onReceivedError: (controller, request, error) {
_webViewHideTimer?.cancel();
if (mounted && !_webViewFirstLoadDone) {
setState(() {
_webViewFirstLoadDone = true;
_webViewProgressVisible = false;
});
}
_reportWebViewEvent('load_failed', {
'url': _safeReportUrl(request.url.toString()),
'isForMainFrame': request.isForMainFrame,
'errorType': error.type.toString(),
'errorDescription': error.description,
});
debugPrint(
'WebView onReceivedError error: ${error.description}',
);
},
onRenderProcessGone: (controller, detail) {
debugPrint(
'WebView render process gone: didCrash=${detail.didCrash}, priority=${detail.rendererPriorityAtExit}',
);
_webViewHideTimer?.cancel();
if (!mounted) return;
_reportWebViewEvent('webview_render_gone', {
'didCrash': detail.didCrash,
'rendererPriorityAtExit': detail
.rendererPriorityAtExit
?.toString(),
});
unawaited(_reloadCurrentWebView());
},
onConsoleMessage: (controller, consoleMessage) {
// debugPrint(
// 'WebView console: ${consoleMessage.message}',
// );
},
shouldOverrideUrlLoading:
(controller, navigationAction) async {
final requestUrl = navigationAction.request.url
?.toString();
if (requestUrl != null &&
requestUrl.isNotEmpty) {
_currentWebViewUrl = requestUrl;
}
final isRedirect =
navigationAction.isRedirect == true;
if (isRedirect && mounted) {
_webViewHideTimer?.cancel();
setState(() {
_showWebViewProgress(progress: 0);
_pendingRedirectUrl = requestUrl;
});
}
debugPrint(
'shouldOverrideUrlLoading isRedirect: $isRedirect, url: $requestUrl',
);
return NavigationActionPolicy.ALLOW;
},
),
return NavigationActionPolicy.ALLOW;
},
),
if (_webViewProgressVisible)
Center(
child: SizedBox(
width: MediaQuery.of(context).size.width > 360
? 320
: MediaQuery.of(context).size.width - 40,
child: LinearProgressIndicator(
value: _webViewProgress > 0
? _webViewProgress
: null,
minHeight: 4,
backgroundColor: Colors.white24,
valueColor: const AlwaysStoppedAnimation<Color>(
Color(0xFF56F0FF),
),
),
if (_webViewProgressVisible)
Center(
child: SizedBox(
width: MediaQuery.of(context).size.width > 360
? 320
: MediaQuery.of(context).size.width - 40,
child: LinearProgressIndicator(
value: _webViewProgress > 0
? _webViewProgress
: null,
minHeight: 4,
backgroundColor: Colors.white24,
valueColor: const AlwaysStoppedAnimation<Color>(
Color(0xFF56F0FF),
),
),
),
],
),
),
],
),
),
],
),
),
],
),
);
}