【问题标题】:Flutter WebView plugin crashes the app when installed on iOS 14+Flutter WebView 插件在 iOS 14+ 上安装时会导致应用崩溃
【发布时间】:2021-01-26 14:45:46
【问题描述】:

当我在装有 iOS 14+ 的 iOS 设备上安装我的应用程序时,当用户转到包含 webview 的页面时,应用程序崩溃。

错误是

Runner[654:91182] *** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[NSTaggedPointerString 计数]:无法识别的选择器发送到实例 0xb0f5a9dc7811cf31”

我使用的代码是:

用户按下按钮时在主页上:

Navigator.push(
          context,
          MaterialPageRoute(
              builder: (context) => SecondPage(url)),
        );

第二页有webview:

class SecondPage extends StatefulWidget {
  SecondPage(this.payload);

  final String payload;

  @override
  State<StatefulWidget> createState() => SecondPageState();
}

class SecondPageState extends State<SecondPage> {
  String _payload;

  @override
  void initState() {
    super.initState();
    _payload = widget.payload;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: MyWebView(
            title: "Narrative App",
            selectedUrl: 'http://iot-center.de/user/adv/$_payload'),
      ),
    );
  }
}

webview 是:

class MyWebView extends StatefulWidget {
  final String title;
  final String selectedUrl;

  MyWebView({
    @required this.title,
    @required this.selectedUrl,
  });

  @override
  _MyWebViewState createState() => _MyWebViewState();
}

class _MyWebViewState extends State<MyWebView> {
  WebViewController _controller;

  final _key = UniqueKey();
  bool _isLoadingPage;

  @override
  void initState() {
    super.initState();
    if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
    _isLoadingPage = true;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.lightBlue,
        title: Text(widget.title),
      ),
      body: Stack(
        children: <Widget>[
          WebView(
            key: _key,
            initialUrl: widget.selectedUrl,
            javascriptMode: JavascriptMode.unrestricted,
            onWebViewCreated: (WebViewController webViewController) {
              this._controller = webViewController;
            },
            onPageFinished: (url) {
              setState(() {
                _isLoadingPage = false;
              });
            },
          ),
          _isLoadingPage
              ? Container(
                  alignment: FractionalOffset.center,
                  child: CircularProgressIndicator(
                    backgroundColor: Colors.lightBlue,
                  ),
                )
              : Container(),
        ],
      ),
      floatingActionButton: favoriteButton(),
    );
  }

  Widget favoriteButton() {
    return FloatingActionButton(
      child: Icon(Icons.share),
      onPressed: () {
        Share.share('Check out this ${widget.selectedUrl}',
            subject: 'Look what I found!');
      },
    );
  }
}

每一个建议都将受到高度赞赏。

【问题讨论】:

    标签: flutter dart webview webview-flutter


    【解决方案1】:

    这是一个 Flutter 错误,flutter 开发人员正在解决这个问题: https://github.com/flutter/flutter/issues/67213#issuecomment-705066599

    【讨论】:

      猜你喜欢
      • 2019-05-02
      • 2019-07-22
      • 1970-01-01
      • 2022-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-01
      相关资源
      最近更新 更多