mod: webview功能完善

This commit is contained in:
guozhigq
2023-06-21 18:19:29 +08:00
parent e738d58766
commit ef2e5b1751
2 changed files with 45 additions and 12 deletions

View File

@ -16,6 +16,8 @@ class WebviewController extends GetxController {
String type = ''; String type = '';
String pageTitle = ''; String pageTitle = '';
final WebViewController controller = WebViewController(); final WebViewController controller = WebViewController();
RxInt loadProgress = 0.obs;
RxBool loadShow = true.obs;
@override @override
void onInit() { void onInit() {
@ -41,11 +43,14 @@ class WebviewController extends GetxController {
// 页面加载 // 页面加载
onProgress: (int progress) { onProgress: (int progress) {
// Update loading bar. // Update loading bar.
loadProgress.value = progress;
}, },
onPageStarted: (String url) {}, onPageStarted: (String url) {},
// 加载完成 // 加载完成
onPageFinished: (String url) async { onPageFinished: (String url) async {
if (type == 'login' && (url.startsWith( loadShow.value = false;
if (type == 'login' &&
(url.startsWith(
'https://passport.bilibili.com/web/sso/exchange_cookie') || 'https://passport.bilibili.com/web/sso/exchange_cookie') ||
url.startsWith('https://m.bilibili.com/'))) { url.startsWith('https://m.bilibili.com/'))) {
try { try {
@ -73,7 +78,7 @@ class WebviewController extends GetxController {
}, },
onWebResourceError: (WebResourceError error) {}, onWebResourceError: (WebResourceError error) {},
onNavigationRequest: (NavigationRequest request) { onNavigationRequest: (NavigationRequest request) {
if (request.url.startsWith('https://www.youtube.com/')) { if (request.url.startsWith('bilibili//')) {
return NavigationDecision.prevent; return NavigationDecision.prevent;
} }
return NavigationDecision.navigate; return NavigationDecision.navigate;

View File

@ -22,8 +22,36 @@ class _WebviewPageState extends State<WebviewPage> {
_webviewController.pageTitle, _webviewController.pageTitle,
style: Theme.of(context).textTheme.titleMedium, style: Theme.of(context).textTheme.titleMedium,
), ),
actions: [
IconButton(
onPressed: () {
_webviewController.controller.reload();
},
icon: const Icon(
Icons.refresh,
size: 22,
), ),
body: WebViewWidget(controller: _webviewController.controller), ),
); const SizedBox(width: 10)
],
),
body: Column(
children: [
Obx(
() => AnimatedContainer(
curve: Curves.easeInOut,
duration: const Duration(milliseconds: 350),
height: _webviewController.loadShow.value ? 4 : 0,
child: LinearProgressIndicator(
key: ValueKey(_webviewController.loadProgress),
value: _webviewController.loadProgress / 100,
),
),
),
Expanded(
child: WebViewWidget(controller: _webviewController.controller),
),
],
));
} }
} }