简体   繁体   English

在 iPhone 的 Flutter 中从 UIWebView 转换为 WKwebview

[英]Converting from UIWebView to WKwebview in Flutter for iPhone

webview_flutter: 0.3.20+2 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.大家好,我是 flutter 的新手,所以我为 Android 的网站创建了 webview,Google play 接受了它。 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,
        )),
      ),
    );
  }
}

Upgrade your webview_flutter package with the latest version as this package now have the support of the WkWebView for iOS.将您的 webview_flutter package 升级为最新版本,因为此 package 现在支持 WkWebView for iOS。

You can find more info about webview_flutter here: https://pub.dev/packages/webview_flutter您可以在此处找到有关 webview_flutter 的更多信息: https://pub.dev/packages/webview_flutter

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM