The method 'SurfaceAndroidWebView' isn't defined for the class '_WebViewExampleState'

Issue

I tried to run an example I got from https://pub.flutter-io.cn/packages/webview_flutter/example to use webview in flutter. But I have this kind of error:

lib/main.dart:43:48: Error: The method ‘SurfaceAndroidWebView’ isn’t defined for the class ‘_WebViewExampleState’. – ‘_WebViewExampleState’ is from ‘package:webview_test/main.dart’ (‘lib/main.dart’).
Try correcting the name to the name of an existing method, or defining a method named ‘SurfaceAndroidWebView’.
if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
^^^^^^^^^^^^^^^^^^^^^

And my code had an error in SurfaceAndroidWebView:
enter image description here

Here is my 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

Thanks in advance!

Solution

After several hours of a workaround, finally, I got the answer. I have to upgrade my flutter to the latest one. And then upgrade my pubspec.yaml.

Answered By – alfianakbar

Answer Checked By – Timothy Miller (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *