[英]flutter web view is not working with ios app
I have created my first flutter module which is having a single web view in it.我已经创建了我的第一个 flutter 模块,它有一个单一的 web 视图。 its working fine when running the module independently or running the .ios/Runner project But when i integrate this module with my ios app and run the app then the web view is disappeared.
它在独立运行模块或运行 .ios/Runner 项目时工作正常但是当我将此模块与我的 ios 应用程序集成并运行该应用程序时,Web 视图消失了。
dart file code :飞镖文件代码:
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))
],
));
}
}
here is the code for app delegate i used:这是我使用的应用程序委托的代码:
lazy var flutterEngine = FlutterEngine()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
flutterEngine.run()
return true
}
Here is the code for iOS viewcontroller for navigation这是用于导航的 iOS 视图控制器的代码
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)
the first output is for module/runner app.第一个输出用于模块/运行器应用程序。
2nd output is for my ios app.第二个输出用于我的 ios 应用程序。
iOS
In order for plugin to work correctly, you need to add new key to ios/Runner/Info.plist为了使插件正常工作,您需要向 ios/Runner/Info.plist 添加新密钥
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSAllowsArbitraryLoadsInWebContent</key>
<true/>
If your URL has some special character then you need to encode the URL like this,如果您的 URL 有一些特殊字符,那么您需要像这样对 URL 进行编码,
WebView( initialUrl: Uri.encodeFull(yourUrl), ... )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.