I have created my first flutter module which is having a single web view in it. 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.
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
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
In order for plugin to work correctly, you need to add new key to 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,
WebView( initialUrl: Uri.encodeFull(yourUrl), ... )
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.