如何在 Flutter 中打开应用内浏览器窗口中的链接以及如何更改浏览器窗口标题
Posted
技术标签:
【中文标题】如何在 Flutter 中打开应用内浏览器窗口中的链接以及如何更改浏览器窗口标题【英文标题】:How to open a link in a in-app browser window in flutter and how to change browser window header 【发布时间】:2021-11-14 21:07:17 【问题描述】:我想知道如何在应用内浏览器中打开链接,就像这样:enter image description here
【问题讨论】:
【参考方案1】:您可以使用flutter_webview 插件实现此目的。 示例代码:
@override
Widget build(BuildContext context)
return Scaffold(
appBar: AppBar(
title: const Text('Flutter WebView example'),
// This drop down menu demonstrates that Flutter widgets can be shown over the web view.
actions: <Widget>[
NavigationControls(_controller.future),
SampleMenu(_controller.future),
],
),
// We're using a Builder here so we have a context that is below the Scaffold
// to allow calling Scaffold.of(context) so we can show a snackbar.
body: Builder(builder: (BuildContext context)
return WebView(
initialUrl: 'https://flutter.dev',
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('https://www.youtube.com/'))
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,
);
),
floatingActionButton: favoriteButton(),
);
【讨论】:
以上是关于如何在 Flutter 中打开应用内浏览器窗口中的链接以及如何更改浏览器窗口标题的主要内容,如果未能解决你的问题,请参考以下文章
如何在外部浏览器而不是应用内(instagram)中打开链接?
如何在 Flutter 中直接从 Play 商店创建这种类型的应用内评分?
如何构造 FCM 推送通知以在 Flutter(Android 和 iOS)的默认系统 Web 浏览器应用中打开指定的 URL