Flutter:webview打开网页
官方文档地址
下方代码来自官方文档,先简单记录下如何通过webview打开某个http地址
添加权限:android/app/src/main/AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET"/>
pubspec.yaml
webview_flutter: ^4.10.0
controller
import 'package:get/get.dart';
import 'package:webview_flutter/webview_flutter.dart';
class LoginController extends GetxController {
LoginController();
WebViewController webViewController = WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted)
..loadRequest(Uri.parse('https://www.baidu.com/'));
_initData() {
update(["login"]);
}
@override
void onReady() {
super.onReady();
_initData();
}
view
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'index.dart';
class LoginPage extends GetView<LoginController> {
const LoginPage({super.key});
@override
Widget build(BuildContext context) {
return GetBuilder<LoginController>(
init: LoginController(),
id: "login",
builder: (_) {
return Scaffold(
appBar: AppBar(title: const Text("login")),
body: WebViewWidget(
controller: controller.webViewController
),
);
},
);
}
}
原文地址:https://blog.csdn.net/qq_40745143/article/details/144269372
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!