在我的flutter webview应用程序中打开一个网站链接



我正在构建一个flutter webview应用程序来显示和使用我的网站,我希望当用户按下属于我网站的链接时,该应用程序会启动该链接,而不是在浏览器上启动。我使用flatter_webview软件包。我该怎么做?如果你想要更多的信息或代码,请告诉我。提前谢谢。

您可以这样使用flutter_inappwebview

import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
class Code extends StatefulWidget {
@override
_CodeState createState() => _CodeState();
}
class _CodeState extends State<Code> {
InAppWebViewController webView;
String url = "";
double progress = 0;
@override
void initState() {
super.initState();
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
final appBar = AppBar(
elevation: 1.0,
backgroundColor: Colors.blueGrey,
title: Text('In-app website'),
centerTitle: true,
leading: IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () {
Navigator.of(context).pop();
},
),
);
final body = InAppWebView(
initialUrl: "https://www.google.com",
initialHeaders: {},
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
debuggingEnabled: true,
),
),
onWebViewCreated: (InAppWebViewController controller) {
webView = controller;
},
onLoadStart: (InAppWebViewController controller, String url) {
setState(() {
this.url = url;
});
},
onLoadStop: (InAppWebViewController controller, String url) async {
setState(() {
this.url = url;
});
},
onProgressChanged: (InAppWebViewController controller, int progress) {
setState(() {
this.progress = progress / 100;
});
},
);
return Scaffold(
appBar: appBar,
body: body,
);
}
}

相关内容

最新更新