flutter WebViewController如何添加header
Posted
技术标签:
【中文标题】flutter WebViewController如何添加header【英文标题】:flutter WebViewController how add header 【发布时间】:2021-06-25 06:40:33 【问题描述】:在我的应用程序中,我使用了 WebViewController。但我不知道,如何将参数传递给标题。这显示一个错误。如何正确传递参数?请帮忙
class _PostRouteScreenState extends State<PostRouteScreen>
final Completer<WebViewController> _controller = Completer<WebViewController>();
@override
void initState()
super.initState();
@override
void dispose()
super.dispose();
@override
Widget build(BuildContext context)
return Scaffold(
appBar: new AppBar(),
body: WebView(
initialUrl: 'https://....../make-route',
headers:"SB-app": "iphone",
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController)
_controller.complete(webViewController);
,
navigationDelegate: (NavigationRequest request)
print('allowing navigation to $request');
return NavigationDecision.navigate;
,
onPageStarted: (String url) async
print('Page started loading: $url');
,
onPageFinished: (String url) async
print('Page finished loading: $url');
,
gestureNavigationEnabled: true,
),
【问题讨论】:
【参考方案1】:尝试省略初始 URL 并使用允许您传递标头的控制器:
body: WebView(
// initialUrl: 'https://....../make-route',
// headers: "SB-app": "iphone",
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController)
_controller.complete(webViewController);
webViewController.loadUrl(
'https://....../make-route',
headers: "SB-app": "iphone",
);
,
【讨论】:
以上是关于flutter WebViewController如何添加header的主要内容,如果未能解决你的问题,请参考以下文章
Flutter webview 拦截所有请求并添加 headers
如何从 UIPopoverController 呈现模态视图?