mod: webview功能完善
This commit is contained in:
@ -16,6 +16,8 @@ class WebviewController extends GetxController {
|
||||
String type = '';
|
||||
String pageTitle = '';
|
||||
final WebViewController controller = WebViewController();
|
||||
RxInt loadProgress = 0.obs;
|
||||
RxBool loadShow = true.obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
@ -41,13 +43,16 @@ class WebviewController extends GetxController {
|
||||
// 页面加载
|
||||
onProgress: (int progress) {
|
||||
// Update loading bar.
|
||||
loadProgress.value = progress;
|
||||
},
|
||||
onPageStarted: (String url) {},
|
||||
// 加载完成
|
||||
onPageFinished: (String url) async {
|
||||
if (type == 'login' && (url.startsWith(
|
||||
'https://passport.bilibili.com/web/sso/exchange_cookie') ||
|
||||
url.startsWith('https://m.bilibili.com/'))) {
|
||||
loadShow.value = false;
|
||||
if (type == 'login' &&
|
||||
(url.startsWith(
|
||||
'https://passport.bilibili.com/web/sso/exchange_cookie') ||
|
||||
url.startsWith('https://m.bilibili.com/'))) {
|
||||
try {
|
||||
var cookies =
|
||||
await WebviewCookieManager().getCookies(HttpString.baseUrl);
|
||||
@ -73,7 +78,7 @@ class WebviewController extends GetxController {
|
||||
},
|
||||
onWebResourceError: (WebResourceError error) {},
|
||||
onNavigationRequest: (NavigationRequest request) {
|
||||
if (request.url.startsWith('https://www.youtube.com/')) {
|
||||
if (request.url.startsWith('bilibili//')) {
|
||||
return NavigationDecision.prevent;
|
||||
}
|
||||
return NavigationDecision.navigate;
|
||||
|
@ -16,14 +16,42 @@ class _WebviewPageState extends State<WebviewPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
centerTitle: false,
|
||||
title: Text(
|
||||
_webviewController.pageTitle,
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
appBar: AppBar(
|
||||
centerTitle: false,
|
||||
title: Text(
|
||||
_webviewController.pageTitle,
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
actions: [
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
_webviewController.controller.reload();
|
||||
},
|
||||
icon: const Icon(
|
||||
Icons.refresh,
|
||||
size: 22,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10)
|
||||
],
|
||||
),
|
||||
),
|
||||
body: WebViewWidget(controller: _webviewController.controller),
|
||||
);
|
||||
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),
|
||||
),
|
||||
],
|
||||
));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user