From db65e7df76084b7840bb9f0c1f52f24776ece6c1 Mon Sep 17 00:00:00 2001 From: Starfallen <36763490+Starfallan@users.noreply.github.com> Date: Tue, 21 Jul 2026 12:30:36 +0800 Subject: [PATCH] fix in-app webview (#2454) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(webview): inApp 模式下拦截非 http(s) scheme,避免 ERR_UNKNOWN_URL_SCHEME * update --------- Co-authored-by: dom --- lib/pages/webview/view.dart | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/pages/webview/view.dart b/lib/pages/webview/view.dart index dd8d18d50..53353f046 100644 --- a/lib/pages/webview/view.dart +++ b/lib/pages/webview/view.dart @@ -317,25 +317,25 @@ class _WebviewPageState extends State { return null; }, shouldOverrideUrlLoading: (controller, navigationAction) async { - if (_inApp) { - return NavigationActionPolicy.ALLOW; + if (!_inApp) { + final hasMatch = await PiliScheme.routePush( + navigationAction.request.url?.uriValue ?? Uri(), + selfHandle: true, + off: _off, + ); + // if (kDebugMode) debugPrint('webview: [$url], [$hasMatch]'); + if (hasMatch) { + progress.value = 1; + return .CANCEL; + } } - late String url = navigationAction.request.url.toString(); - bool hasMatch = await PiliScheme.routePush( - navigationAction.request.url?.uriValue ?? Uri(), - selfHandle: true, - off: _off, - ); - // if (kDebugMode) debugPrint('webview: [$url], [$hasMatch]'); - if (hasMatch) { - progress.value = 1; - return NavigationActionPolicy.CANCEL; - } else if (_prefixRegex.hasMatch(url)) { + final url = navigationAction.request.url.toString(); + if (_prefixRegex.hasMatch(url)) { if (context.mounted) { - SnackBar snackBar = SnackBar( - content: const Text('当前网页将要打开外部链接,是否打开'), - showCloseIcon: true, + final snackBar = SnackBar( persist: false, + showCloseIcon: true, + content: const Text('当前网页将要打开外部链接,是否打开'), action: SnackBarAction( label: '打开', onPressed: () => PageUtils.launchURL(url), @@ -344,10 +344,10 @@ class _WebviewPageState extends State { ScaffoldMessenger.of(context).showSnackBar(snackBar); } progress.value = 1; - return NavigationActionPolicy.CANCEL; + return .CANCEL; } - return NavigationActionPolicy.ALLOW; + return .ALLOW; }, ), ),