Reputation: 13
webview_flutter: 0.3.20+2
Hello everyone, I am very new with flutter so I created webview for a website for Android and Google play accepted it. nowadays I am reading that apple does not accept such apps anymore. What is the solution?
I did not find any article about this subject. Could any one help please. Thank you in advance.
here is the code:
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'dart:async';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'x',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(
title: 'x',
url: 'https://apple.de/'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title, this.url});
final String title;
final String url;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
WebViewController _controller;
final Completer<WebViewController> _controllerCompleter =
Completer<WebViewController>();
//Make sure this function return Future<bool> otherwise you will get an error
Future<bool> _onWillPop(BuildContext context) async {
if (await _controller.canGoBack()) {
_controller.goBack();
return Future.value(false);
} else {
return Future.value(true);
}
}
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () => _onWillPop(context),
child: Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: SafeArea(
child: WebView(
key: UniqueKey(),
onWebViewCreated: (WebViewController webViewController) {
_controllerCompleter.future.then((value) => _controller = value);
_controllerCompleter.complete(webViewController);
},
javascriptMode: JavascriptMode.unrestricted,
initialUrl: widget.url,
)),
),
);
}
}
Upvotes: 1
Views: 2526
Reputation: 388
Upgrade your webview_flutter package with the latest version as this package now have the support of the WkWebView for iOS.
You can find more info about webview_flutter here : https://pub.dev/packages/webview_flutter
Upvotes: 2