我创建了我的第一个Flutter模块,其中包含单个Web视图。 独立运行模块或运行.ios / Runner项目时,其工作正常 但是,当我将此模块与ios应用程序集成并运行该应用程序时,Web视图便消失了。
dart文件代码:
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:webview_flutter/webview_flutter.dart';
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Material App',
theme: ThemeData.light(),
home: Home(),
);
}
}
// ignore: must_be_immutable
class Home extends StatelessWidget {
String _url = "https://www.google.com";
final _key = UniqueKey();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Web Viewwww"),
leading: IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () => SystemNavigator.pop(
animated: true) /*Navigator.pop(context, true)*/,
)),
body: Column(
children: [
Expanded(
child: WebView(
key: _key,
javascriptMode: JavascriptMode.unrestricted,
initialUrl: _url))
],
));
}
}
这是我使用的应用程序委托的代码:
lazy var flutterEngine = FlutterEngine()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
flutterEngine.run()
return true
}
这是iOS viewcontroller的导航代码
let engin = (UIApplication.shared.delegate as! AppDelegate).flutterEngine
let myflutterVC = FlutterViewController(engine: engin, nibName: nil, bundle: nil)
myflutterVC.modalPresentationStyle = .fullScreen
present(myflutterVC, animated: true, completion: nil)
答案 0 :(得分:1)
iOS
为了使插件正常工作,您需要在 ios/Runner/Info.plist 中添加新密钥
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSAllowsArbitraryLoadsInWebContent</key>
<true/>