feat: 添加图标大小限制和无缓存请求头,优化 WebView 加载逻辑

This commit is contained in:
Booker
2026-05-26 15:15:46 +07:00
parent b85422c1bc
commit 81f0f342a9
2 changed files with 45 additions and 3 deletions

View File

@@ -15,6 +15,11 @@ const _shellBackground = Color(0xFFF8FBFF);
const _shellAccent = Color(0xFF0089FF);
const _shellSubText = Color(0xFF8E9AB0);
const _resumeCoverDuration = Duration(milliseconds: 700);
const _noCacheHeaders = {
'Cache-Control': 'no-cache, no-store, max-age=0, must-revalidate',
'Pragma': 'no-cache',
'Expires': '0',
};
const _shellBrandingChannel =
MethodChannel('io.openim.flutter.im_webview_app/shell_branding');
const _shellMediaPermissionBridgeScript = r'''
@@ -221,7 +226,8 @@ class _H5ShellPageState extends State<H5ShellPage> with WidgetsBindingObserver {
appName: widget.shellBranding.appName,
appLogo: widget.shellBranding.appLogo,
);
_controller = _buildController()..loadRequest(Uri.parse(_homeUrl));
_controller = _buildController();
unawaited(_loadHome());
}
@override
@@ -439,6 +445,27 @@ class _H5ShellPageState extends State<H5ShellPage> with WidgetsBindingObserver {
return _runJavaScriptSafely(_stopWebMediaScript);
}
Future<void> _loadHome() async {
if (mounted) {
setState(() {
_loadError = null;
_progress = 0;
_showShellCover = true;
});
}
try {
await _controller.clearCache();
} catch (_) {
// Some WebView implementations can reject cache operations during setup.
}
await _controller.loadRequest(
Uri.parse(_homeUrl),
headers: _noCacheHeaders,
);
}
Future<NavigationDecision> _handleNavigationRequest(
NavigationRequest request,
) async {
@@ -568,7 +595,7 @@ class _H5ShellPageState extends State<H5ShellPage> with WidgetsBindingObserver {
if (_loadError != null)
_ErrorPanel(
message: _loadError!,
onRetry: () => _controller.loadRequest(Uri.parse(_homeUrl)),
onRetry: () => unawaited(_loadHome()),
),
],
),