【问题标题】:The method 'SurfaceAndroidWebView' isn't defined for the class '_WebViewExampleState'没有为类“_WebViewExampleState”定义方法“SurfaceAndroidWebView”
【发布时间】:2021-01-30 17:58:55
【问题描述】:

我尝试运行从https://pub.flutter-io.cn/packages/webview_flutter/example 获得的示例,以在 Flutter 中使用 webview。但是我有这种错误:

lib/main.dart:43:48:错误:没有为类“_WebViewExampleState”定义方法“SurfaceAndroidWebView”。 - '_WebViewExampleState' 来自'package:webview_test/main.dart' ('lib/main.dart')。 尝试将名称更正为现有方法的名称,或定义名为“SurfaceAndroidWebView”的方法。 if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView(); ^^^^^^^^^^^^^^^^^^^^^

我的代码在 SurfaceAndroidWebView 中出现错误:

这是我的 pubspec.yaml:

name: webview_test
description: A new Flutter application.

publish_to: 'none'

version: 1.0.0+1

environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  webview_flutter:
  cupertino_icons: ^0.1.3

dev_dependencies:
  flutter_test:
    sdk: flutter

flutter:
  uses-material-design: true
  assets:
    - assets/sample_audio.ogg

提前致谢!

【问题讨论】:

标签: flutter flutterwebviewplugin


【解决方案1】:

甜!我有同样的问题并想通了。我在 pubspec.yaml 中定义了旧版本的 webview_flutter。所以,当我尝试做一个颤振的 pub get 时,它没有得到我认为的最新版本的 webview。

在 pubspec.yaml 我有这个(旧版本): webview_flutter: ^0.3.22+1

我改成了这个(截至本文的最新版本): webview_flutter: ^1.0.7

然后我去控制台运行:flutter pub get

现在我的应用可以识别 SurfaceAndroidWebView 了!

在这方面我是新手,所以也许其他人已经尝试过,但也许其他人不知道。

【讨论】:

    【解决方案2】:

    您需要导入 SurfaceAndroidWebView 页面。

    
    import './SurfaceAndroidWebView.dart';
    
    

    【讨论】:

    • 没用。 “URI 的目标不存在:'./SurfaceAndroidWebView.dart'。”
    【解决方案3】:

    经过几个小时的解决方法,我终于得到了答案。我必须将我的颤振升级到最新的。然后升级我的 pubspec.yaml。

    【讨论】:

    • 这对我不起作用。你还做了什么吗?你是稳定版还是测试版?
    【解决方案4】:

    Android minSdkVersion 应该是 19:

    将以下内容添加到 /android/app/build.gradle

    android {
        defaultConfig {
            // Required by the Flutter WebView plugin.
            minSdkVersion 19
        }
      }
    

    【讨论】:

      猜你喜欢
      • 2021-09-02
      • 2019-06-24
      • 2020-09-10
      • 2019-05-23
      • 1970-01-01
      • 2022-11-21
      • 2021-08-02
      • 2021-10-19
      • 2020-04-20
      相关资源
      最近更新 更多