官方文档地址
下方代码来自官方文档,先简单记录下如何通过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"]);}@overridevoid 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});@overrideWidget build(BuildContext context) {return GetBuilder<LoginController>(init: LoginController(),id: "login",builder: (_) {return Scaffold(appBar: AppBar(title: const Text("login")),body: WebViewWidget(controller: controller.webViewController),);},);}
}