升级flutter_inappwebview后出现命名参数未定义错误,求迁移解决方案
flutter_inappwebview版本升级API调整方案
核心原因
你遇到的参数未定义报错,是因为升级到了flutter_inappwebview 6.x及以上的大版本,该版本对原有API做了批量不兼容更新,对应修改规则如下:
各报错参数替换规则
initialHeadersRequest:已废弃,请求头直接配置到URLRequest的headers属性中即可initialOptions:重命名为initialSettings,配套的InAppWebViewGroupOptions改为InAppWebViewSettingsdebuggingEnabled:重命名为isInspectableonWebViewCreated:重命名为onControllerReceivedonLoadStart:重命名为onPageStarted,回调参数url类型从String调整为Uri?onLoadStop:重命名为onPageFinished,回调参数url类型从String调整为Uri?
修改后完整代码
import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart'; import 'package:gec_app/Menu.dart'; Future main() async { WidgetsFlutterBinding.ensureInitialized(); } class AboutUs extends StatefulWidget { @override _AboutUsState createState() => new _AboutUsState(); } class _AboutUsState extends State<AboutUs> { InAppWebViewController? webView; @override void initState() { super.initState(); } @override void dispose() { super.dispose(); } @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar( title: const Text('Visit Us'), leading: new IconButton( icon: new Icon(Icons.arrow_back), onPressed: () { Navigator.push(context, MaterialPageRoute(builder: (context) => HomeScreen())); })), body: Container( child: Column(children: <Widget>[ Expanded( child: InAppWebView( initialUrlRequest: URLRequest( url: Uri.parse("https://www.gecgh.org/"), headers: {}, ), initialSettings: InAppWebViewSettings( isInspectable: true, preferredContentMode: UserPreferredContentMode.DESKTOP, ), onControllerReceived: (InAppWebViewController controller) { webView = controller; }, onPageStarted: (InAppWebViewController controller, Uri? url) {}, onPageFinished: (InAppWebViewController controller, Uri? url) async {}, )) ])), ), ); } }
内容的提问来源于stack exchange,提问作者Manuel
相关产品推荐
相关产品推荐

