0

I'm trying to write an app with the use of the WebView in flutter. However, i'm receiving the error described below:

compiler message:
/C:/flutter/.pub-cache/hosted/pub.dartlang.org/webview_flutter-0.3.22+1/lib/webview_flutter.Dart:395:37: Error: The argument type 'AutoMediaPlaybackPolicy/*1*/' can't be assigned to the parameter type 'AutoMediaPlaybackPolicy/*2*/'.
 - 'AutoMediaPlaybackPolicy/*1*/' is from 'package:webview_flutter/webview_flutter.Dart' ('/C:/flutter/.pub-cache/hosted/pub.dartlang.org/webview_flutter-0.3.22+1/lib/webview_flutter.Dart').
 - 'AutoMediaPlaybackPolicy/*2*/' is from 'package:webview_flutter/webview_flutter.dart' ('/C:/flutter/.pub-cache/hosted/pub.dartlang.org/webview_flutter-0.3.22+1/lib/webview_flutter.dart').
    autoMediaPlaybackPolicy: widget.initialMediaPlaybackPolicy,
                                    ^
/C:/flutter/.pub-cache/hosted/pub.dartlang.org/webview_flutter-0.3.22+1/lib/webview_flutter.Dart:401:28: Error: The argument type 'JavascriptMode/*1*/' can't be assigned to the parameter type 'JavascriptMode/*2*/'.
 - 'JavascriptMode/*1*/' is from 'package:webview_flutter/webview_flutter.Dart' ('/C:/flutter/.pub-cache/hosted/pub.dartlang.org/webview_flutter-0.3.22+1/lib/webview_flutter.Dart').
 - 'JavascriptMode/*2*/' is from 'package:webview_flutter/webview_flutter.dart' ('/C:/flutter/.pub-cache/hosted/pub.dartlang.org/webview_flutter-0.3.22+1/lib/webview_flutter.dart').
    javascriptMode: widget.javascriptMode,
                           ^
/C:/flutter/.pub-cache/hosted/pub.dartlang.org/webview_flutter-0.3.22+1/lib/webview_flutter.Dart:426:31: Error: A value of type 'JavascriptMode/*1*/' can't be assigned to a variable of type 'JavascriptMode/*2*/'.
 - 'JavascriptMode/*1*/' is from 'package:webview_flutter/webview_flutter.dart' ('/C:/flutter/.pub-cache/hosted/pub.dartlang.org/webview_flutter-0.3.22+1/lib/webview_flutter.dart').
 - 'JavascriptMode/*2*/' is from 'package:webview_flutter/webview_flutter.Dart' ('/C:/flutter/.pub-cache/hosted/pub.dartlang.org/webview_flutter-0.3.22+1/lib/webview_flutter.Dart').
    javascriptMode = newValue.javascriptMode;
                              ^
/C:/flutter/.pub-cache/hosted/pub.dartlang.org/webview_flutter-0.3.22+1/lib/webview_flutter.Dart:439:21: Error: The argument type 'JavascriptMode/*1*/' can't be assigned to the parameter type 'JavascriptMode/*2*/'.
 - 'JavascriptMode/*1*/' is from 'package:webview_flutter/webview_flutter.Dart' ('/C:/flutter/.pub-cache/hosted/pub.dartlang.org/webview_flutter-0.3.22+1/lib/webview_flutter.Dart').
 - 'JavascriptMode/*2*/' is from 'package:webview_flutter/webview_flutter.dart' ('/C:/flutter/.pub-cache/hosted/pub.dartlang.org/webview_flutter-0.3.22+1/lib/webview_flutter.dart').
    javascriptMode: javascriptMode,

I created a separate app only using WebView (to test my environment) and that's running correctly. I don't understand because in the first application (with error) presents the issue. If I remove all code related to WebView the compiler message still the same, i.e, the problem happens when I do the import in the package. The pubspec.yaml is identical in the two Applications.

The respective code:

import 'package:webview_flutter/webview_flutter.Dart';

class WebViewContainer extends StatefulWidget {
  final url;
  WebViewContainer(this.url);
  @override
  createState() => _WebViewContainerState(this.url);
}
class _WebViewContainerState extends State<WebViewContainer> {
  var _url;
  final _key = UniqueKey();
  _WebViewContainerState(this._url);
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(),
        body: Column(
          children: [
            Expanded(
                child: WebView(
                    key: _key,
                    javascriptMode: JavascriptMode.unrestricted,
                    initialUrl: _url))
          ],
        ));
  }
}

The piece of code where the action happens:

class CursoDeNoivos extends  StatelessWidget{
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Curso de Noivos"),
        centerTitle: true,
        backgroundColor: Colors.deepPurple,
      ),
      body:SingleChildScrollView(
        child: Column(
          children: <Widget>[
Expanded(
                  child: Padding(
                      padding: EdgeInsets.only(left: 1.0, top: 1.0, right: 1.0, bottom: 1.0),
                      child: Container(
                        height: button_height,
                        child: buildIconButton("Inscrições", _insc, context, Icons.add_circle_outline),
                      )
                  ),
                )
              ],

The action when the button is pressed:

Widget buildIconButton(String _text, Object _obj, BuildContext  _context, IconData _icon) {
  return RaisedButton.icon(
      onPressed: (){
        //Navigator.push(_context, MaterialPageRoute(builder: (context) => _obj));
        Navigator.push(_context, MaterialPageRoute(builder: (context) => WebViewContainer('https://google.com')));
      },
      icon: Icon(_icon, color: Colors.white, size: 30.0,),
      label: Text(_text, style: TextStyle(color: Colors.white, fontSize: 20), textAlign: TextAlign.left),
      color: Colors.deepPurple,
  );
}

The pubspec.yaml file:

# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1

environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter


  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.3
  webview_flutter: ^0.3.3

dev_dependencies:
  flutter_test:
    sdk: flutter

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true
  assets:
    - images/casados.jpg
    - images/noivos.jpg

The Flutter doctor results:

C:\flutter\bin\flutter.bat doctor --verbose
[√] Flutter (Channel beta, v1.17.0, on Microsoft Windows [versão 10.0.18362.836], locale pt-BR)
    • Flutter version 1.17.0 at C:\flutter
    • Framework revision e6b34c2b5c (4 weeks ago), 2020-05-02 11:39:18 -0700
    • Engine revision 540786dd51
    • Dart version 2.8.1

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.0-rc4)
    • Android SDK at C:\Users\feps\AppData\Local\Android\sdk
    • Platform android-29, build-tools 30.0.0-rc4
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)
    • All Android licenses accepted.

[√] Android Studio (version 3.6)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 45.1.1
    • Dart plugin version 192.7761
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)

[√] VS Code, 64-bit edition (version 1.24.0)
    • VS Code at C:\Program Files\Microsoft VS Code
    • Flutter extension version 2.21.1

[√] Connected device (1 available)
    • Android SDK built for x86 • emulator-5554 • android-x86 • Android 9 (API 28) (emulator)

• No issues found!
Process finished with exit code 0

I've got no idea about the cause of the issue... (I'm new in Flutter or Apps development)

Fernando
  • 81
  • 1
  • 6
  • Can you also share the `pubspec.yaml` and `flutter doctor` summary. On the surface it looks like a install malfunction. Please try this solution from this [post](https://stackoverflow.com/questions/55399209/update-flutter-dependencies-in-pub-cache). – Abhilash Chandran Jun 01 '20 at 20:51
  • Hi Abhilash, I updated the question with the requested information. Thanks! – Fernando Jun 02 '20 at 13:05

0 Answers0