【问题标题】:webView don't work in flutter [ERROR:flutter/lib/ui/ui_dart_state.cc(157)]webView 在颤振中不起作用 [错误:flutter/lib/ui/ui_dart_state.cc(157)]
【发布时间】:2020-02-21 17:51:14
【问题描述】:

我添加了 pubspec.yaml webview_flutter: ^0.3.19+8 我使用 Flutter 版本 1.12.13+hotfix.8

这是我的代码

import 'package:webview_flutter/webview_flutter.dart';

void main() => runApp(MaterialApp(
  home: app(),
));

class app extends StatefulWidget {
  @override
  _appState createState() => _appState();
}

class _appState extends State<app> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('App mobile'),
      ),
      body: Container(
        constraints: BoxConstraints(maxHeight: 500),
        child: WebView(
          initialUrl: "https://google.com",
        ),
      )
    );
  }
}

但在运行并单击white 模拟器屏幕后,在标签运行中我有这个...

E/flutter ( 9570): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(error, java.lang.IllegalStateException: Sending touch to an unknown view with id: 1
E/flutter ( 9570):  at io.flutter.plugin.platform.PlatformViewsController$1.onTouch(PlatformViewsController.java:206)
E/flutter ( 9570):  at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.touch(PlatformViewsChannel.java:168)
...

我将不胜感激...

【问题讨论】:

    标签: android flutter webview


    【解决方案1】:

    我用过这个并且工作正常,我想你错过了使用controller

    import 'dart:async';
    import 'package:flutter/material.dart';
    import 'package:webview_flutter/webview_flutter.dart';
    
    class WebViewScreen extends StatefulWidget {
      final String title;
      final String selectedUrl;
    
      WebViewScreen({@required this.title, @required this.selectedUrl});
    
      @override
      _WebViewScreenState createState() => _WebViewScreenState();
    }
    
    class _WebViewScreenState extends State<WebViewScreen> {
      Completer<WebViewController> _controller = Completer<WebViewController>();
      bool isLoading = true;
    
      @override
      void initState() {
        super.initState();
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text(widget.title),
          ),
          body: WebView(
            initialUrl: widget.selectedUrl,
            onWebViewCreated: (WebViewController webViewController) {
              _controller.complete(webViewController);
            },
          ),
        );
      }
    }
    
    

    【讨论】:

      【解决方案2】:

      如果您在发布模式下遇到此错误,请检查您的清单文件中的“android.permission.INTERNET”权限。

      【讨论】:

        猜你喜欢
        • 2021-06-30
        • 2020-12-05
        • 2022-01-05
        • 1970-01-01
        • 2020-06-07
        • 2021-11-20
        • 1970-01-01
        • 1970-01-01
        • 2019-07-21
        相关资源
        最近更新 更多