The argument type 'String' can't be assigned to the parameter type 'Uri'

Good Day all,

Hoping someone can point me in the right direction, with my android Studio flutter Project I had to update the dependencies the resolvable versions, in doing so it has created a few problems.

I am now getting the errors,

  • error: Target of URI doesn’t exist: ‘package:audioplayers/web/audioplayers_web.dart’. (uri_does_not_exist at [Dash] lib\generated_plugin_registrant.dart:9)

  • error: Undefined name ‘AudioplayersPlugin’. (undefined_identifier at [Dash] lib\generated_plugin_registrant.dart:19)

  • error: The method ‘play’ isn’t defined for the type ‘AudioCache’. (undefined_method at [Dash] lib\src\bridge\bridge_ui_builder_functions.dart:99)

  • error: The argument type ‘String’ can’t be assigned to the parameter type ‘Uri’. (argument_type_not_assignable at [Dash] lib\src\web_view\web_view_container.dart:143)

  • error: The argument type ‘String’ can’t be assigned to the parameter type ‘Uri’. (argument_type_not_assignable at [Dash] lib\src\web_view\web_view_container.dart:146)

I have tried looking for various solutions online but have struck out.

As always your help is appreciated.

Kind Regards,
Raymond

I have resolve the first three errors by reverting back to the audioplayers dependency as referenced in the git repository pubspec.yaml however the last to errors are still persisting.

Kind Regards,
Raymond

Hello, @Raymond_Woodley.

Can you share with me your code that throws this errors?

But in general, the error says that you are trying to assign a String value in the Uri. To do this, you need to assign as follows:
Uri uri = Uri.parse('your string url');

Best Regards, Nikita.

Hello @Nikita_Fedorishchev,

Thank you for your reply, please see code throwing both errors below,

Issue are located in the web_view_container.dart

var uri = navigationAction.request.url!;

          if (![
            "http",
            "https",
            "file",
            "chrome",
            "data",
            "javascript",
            "about"
          ].contains(uri.scheme)) {
            if (await canLaunchUrl(uri.toString())) {
              // Launch the App
              await launchUrl(
                uri.toString(),
              );
              // and cancel the request
              return NavigationActionPolicy.CANCEL;
            }
          }

Thank you for your assistance.

Kind Regards,
Raymond

1st error

if (await canLaunchUrl(uri.toString()))

2nd error
uri.toString(),

What device are you trying to run the app on?
Also what the version of url_launcher(you can check at pubspec.yaml) are you using?

url_launcher: ^6.0.10

At this point I am trying to just run the app on the android emulator. Before creating an app bundle.

Try to replace code into this function to this:

shouldOverrideUrlLoading: (controller, navigationAction) async {
          var uri = navigationAction.request.url!;

          if (![
            "http",
            "https",
            "file",
            "chrome",
            "data",
            "javascript",
            "about"
          ].contains(uri.scheme)) {
            if (await canLaunchUrl(uri)) {
              // Launch the App
              await launchUrl(
                uri,
              );
              // and cancel the request
              return NavigationActionPolicy.CANCEL;
            }
          }

          return NavigationActionPolicy.ALLOW;
        },

Hi Nikita,

I really appreciate your help,

Kind Regards,
Raymond