我已經使用 InAppWebView 包在 flutter 中使用簡單的 webview 卡住了幾個星期。關鍵是它根本沒有回應,基本上我看到它可以通過減少60%的百分比來解決,但是我無法實作讓客戶滿意的任何東西。有人提出了如何在不接觸服務器任何內容的情況下以百分比形式減少 webview 的內容。
粘貼部分代碼:
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Demo',
style: TextStyle(height: 5, fontSize: 10),
),
backgroundColor: Colors.transparent,
toolbarHeight: 10,
),
body: Container(
child: Column(children: <Widget>[
Expanded(
child: Stack(
children: [
InAppWebView(
initialUrlRequest:
URLRequest(url: Uri.parse("[SERVER ADDRESS]")),
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
preferredContentMode: UserPreferredContentMode.DESKTOP,
),
),
onWebViewCreated: (InAppWebViewController controller) {
webView = controller;
},
onl oadStart: ( controler, url) {
},
onl oadStop: ( controller, url) async {
},
)
])),
])
),
),
);
}
我將不勝感激任何幫助。感謝!
uj5u.com熱心網友回復:
請試試這個包 webview_flutter: ^3.0.0
uj5u.com熱心網友回復:
我也試過 webview_flutter,但我發現了同樣的問題,它不是很敏感,我必須減少它的百分比。
粘貼代碼:
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white10,
appBar: AppBar(
title: const Text('DEMO'),
actions: <Widget>[
NavigationControls(_controller.future),
SampleMenu(_controller.future),
],
),
body: Builder(builder: (BuildContext context) {
return WebView(
initialUrl: '{SERVER ADDRESS}',
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) {
_controller.complete(webViewController);
},
onProgress: (int progress) {
print('WebView is loading (progress : $progress%)');
},
javascriptChannels: <JavascriptChannel>{
_toasterJavascriptChannel(context),
},
navigationDelegate: (NavigationRequest request) {
if (request.url.startsWith('{SERVER ADDRESS}')) {
print('blocking navigation to $request}');
return NavigationDecision.prevent;
}
print('allowing navigation to $request');
return NavigationDecision.navigate;
},
onPageStarted: (String url) {
print('Page started loading: $url');
},
onPageFinished: (String url) {
print('Page finished loading: $url');
},
gestureNavigationEnabled: true,
backgroundColor: const Color(0x00000000),
);
}),
);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/402361.html
標籤:
上一篇:如何讓我的隨機問題不重復?
