下方代码来自官方文档,先简单记录下如何通过webview打开某个http地址
添加权限:android/app/src/main/AndroidManifest.xml
js
<uses-permission android:name="android.permission.INTERNET"/>
pubspec.yaml
js
webview_flutter: ^4.10.0
controller
js
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
js
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
),
);
},
);
}
}