From c7c69c3db0f2c6281227315f333d0bd284b54ac8 Mon Sep 17 00:00:00 2001 From: dom Date: Sun, 26 Apr 2026 20:01:29 +0800 Subject: [PATCH] opt android webview Signed-off-by: dom --- lib/pages/webview/view.dart | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/pages/webview/view.dart b/lib/pages/webview/view.dart index 2e64eaa7b..c7fab7474 100644 --- a/lib/pages/webview/view.dart +++ b/lib/pages/webview/view.dart @@ -1,5 +1,6 @@ import 'dart:io'; +import 'package:PiliPlus/common/widgets/flutter/pop_scope.dart'; import 'package:PiliPlus/http/browser_ua.dart'; import 'package:PiliPlus/main.dart'; import 'package:PiliPlus/models/common/webview_menu_type.dart'; @@ -85,10 +86,11 @@ class _WebviewPageState extends State { ), ); } - return Scaffold( + Widget child = Scaffold( appBar: widget.url != null ? null : AppBar( + leading: BackButton(onPressed: Get.back), title: Obx( () => Text( title.value.isNotEmpty ? title.value : _url, @@ -351,5 +353,24 @@ class _WebviewPageState extends State { ), ), ); + if (Platform.isAndroid) { + return popScope( + canPop: false, + onPopInvokedWithResult: (didPop, result) async { + if (didPop) { + return; + } + final canGoBack = await _webViewController?.canGoBack(); + if (!mounted) return; + if (canGoBack ?? false) { + _webViewController!.goBack(); + } else { + Get.back(); + } + }, + child: child, + ); + } + return child; } }