Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regarding Flutter + Flutter Web packages not being recognized on pub.dev #3277

Closed
luanpotter opened this issue Jan 29, 2020 · 11 comments
Closed

Comments

@luanpotter
Copy link
Contributor

I just uploaded a new version of the package audioplayers including the flutter web files.

However, pub does not like the web files:

See: https://pub.dev/packages/audioplayers#-analysis-tab-

Fix lib/audioplayers_web.dart. (-95.82 points)
Analysis of lib/audioplayers_web.dart failed with 11 errors, 2 hints, including:
line 3 col 8: Target of URI doesn't exist: 'dart:web_audio'.
line 8 col 7: Undefined class 'AudioContext'.
line 8 col 32: The function 'AudioContext' isn't defined.
line 17 col 3: Undefined class 'AudioBuffer'.
line 18 col 3: Undefined class 'AudioBufferSourceNode'.

I also find it weird that I have to add the audioplayer_web.dart file inside the lib folder. All other platforms have dedicated folders outside the lib folder. This file is the implementation for web, should be placed on a web folder outside the lib folder, just like ios, android and macos. However when I do that, I cannot properly run the example app on web.

Can you give me some directions on how to proceed? Having such a low score on pub is not desirable, I'm sure there is a way to configure everything properly.

@isoos
Copy link
Collaborator

isoos commented Jan 29, 2020

@luanpotter: thanks for reporting this, seems like an edge case in Flutter web + dartanalyzer, we'll need to dig into it what's going on.

I also find it weird that I have to add the audioplayer_web.dart file inside the lib folder.

Could you please link where this is recommended?

@luanpotter
Copy link
Contributor Author

Hi @isoos , thanks for looking into this!

So I'm in contact with Mariam from Google. I got some instructions and I was following this article. Mostly it suggests creating a separated package, but since I'm the owner of the original audioplayers, I thought I might do it on the same (the same way all other platforms reside on the same plugin, different implementation folders).

The article directs us to add a <plugin>_web.dart file inside the lib folder. So that is my confusion. Also I tried adding a web folder outside of lib and adding the file there, but then on the example app for web I cannot make it properly import that file.

@isoos
Copy link
Collaborator

isoos commented Jan 30, 2020

Maybe the author @hterkelsen can comment on this? Or some another official Flutter channel: https://flutter.dev/community

I am not aware what the official layout recommendation on this is, and I couldn't find example repositories with similar layouts. If there is anything we shall change in the analysis or suggestions, I'm happy to help with that, but I cannot recommend on how Flutter (esp. the new web platform) should be used.

@harryterkelsen
Copy link

Unfortunately, the only web-specific dart: libraries available in Flutter are dart:html, dart:js and dart:js_util. You can use package:js to create JS-interop classes for the dart:web_audio classes you are using and most likely only have to change the import in audioplayers_web.dart from dart:web_audio to your library containing your JS-interop classes.

As for layout: you could create an web/ directory which would be another package which just has the web-specific code. Unfortunately, you will also need to add stub Android and iOS folders in your web plugin... The reason that you can't just have a web/ folder containing just the Dart files is that those files wouldn't be able to be imported since they wouldn't be inside of a Dart package.

@luanpotter
Copy link
Contributor Author

@hterkelsen, thanks for your input.

Unfortunately, the only web-specific dart: libraries available in Flutter are dart:html, dart:js and dart:js_util

I'm not sure I follow, I am using dart:web_audio and tested in Flutter web and it worked. It is certainly available. It just doesn't work on pub.

About the layout, I understand it could be technical difficult, and I'm certainly ok with keeping audioplayers_web.dart inside, but I propose as a suggestion the structure I mentioned as I think it's more clear and more in-line with what my expectations are.

@isoos
Copy link
Collaborator

isoos commented Feb 1, 2020

I'm not sure I follow, I am using dart:web_audio and tested in Flutter web and it worked. It is certainly available. It just doesn't work on pub.

@luanpotter: Could you please run the following commands in your package directory and copy their output here:

flutter --version
flutter analyze
[path-to-flutter-sdk]/bin/cache/dart-sdk/bin/dartanalyzer lib/

I have a fear that we are getting another edge case where the Flutter-included SDK slightly differs from the APIs provided by Flutter SDK. A prior bug on that was this: flutter/flutter#23664

@luanpotter
Copy link
Contributor Author

There you have it:

[luan@aurora audioplayers]$ flutter --version
Flutter 1.14.7-pre.83 • channel master • https://github.com/flutter/flutter.git
Framework • revision e10df3c1a6 (13 hours ago) • 2020-02-01 11:23:01 +0800
Engine • revision e625e174c5
Tools • Dart 2.8.0 (build 2.8.0-dev.6.0 5ae5aff640)
[luan@aurora audioplayers]$ flutter analyze
Running "flutter pub get" in audioplayers...                        0.7s
Analyzing audioplayers...                                               

   info • 'seekCompleteHandler' is deprecated and shouldn't be used • example/lib/main.dart:228:27 • deprecated_member_use
  error • Target of URI doesn't exist: 'dart:web_audio' • lib/audioplayers_web.dart:3:8 • uri_does_not_exist
  error • Undefined class 'AudioContext' • lib/audioplayers_web.dart:8:7 • undefined_class
  error • The function 'AudioContext' isn't defined • lib/audioplayers_web.dart:8:32 • undefined_function
  error • Undefined class 'AudioBuffer' • lib/audioplayers_web.dart:17:3 • undefined_class
  error • Undefined class 'AudioBufferSourceNode' • lib/audioplayers_web.dart:18:3 • undefined_class
  error • Undefined class 'GainNode' • lib/audioplayers_web.dart:19:3 • undefined_class
  error • Undefined class 'AudioBuffer' • lib/audioplayers_web.dart:21:18 • undefined_class
  error • The name 'AudioBuffer' isn't a type so it can't be used as a type argument • lib/audioplayers_web.dart:85:15 • non_type_as_type_argument
  error • The name 'AudioBuffer' isn't a type so it can't be used as a type argument • lib/audioplayers_web.dart:98:10 • non_type_as_type_argument
  error • Undefined class 'AudioBuffer' • lib/audioplayers_web.dart:105:11 • undefined_class
  error • Undefined class 'AudioBuffer' • lib/audioplayers_web.dart:116:11 • undefined_class
   info • The value of the local variable 'isLocal' isn't used • lib/audioplayers_web.dart:134:22 • unused_local_variable
   info • This function has a return type of 'Future<dynamic>', but doesn't end with a return statement • test/audioplayers_test.dart:8:36 • missing_return

14 issues found. (ran in 17.3s)
[luan@aurora audioplayers]$ /home/luan/softwares/flutter/bin/cache/dart-sdk/bin/dartanalyzer lib/
Analyzing lib...
  error • Target of URI doesn't exist: 'dart:web_audio'. • lib/audioplayers_web.dart:3:8 • uri_does_not_exist
  error • Undefined class 'AudioContext'. • lib/audioplayers_web.dart:8:7 • undefined_class
  error • The function 'AudioContext' isn't defined. • lib/audioplayers_web.dart:8:32 • undefined_function
  error • Undefined class 'AudioBuffer'. • lib/audioplayers_web.dart:17:3 • undefined_class
  error • Undefined class 'AudioBufferSourceNode'. • lib/audioplayers_web.dart:18:3 • undefined_class
  error • Undefined class 'GainNode'. • lib/audioplayers_web.dart:19:3 • undefined_class
  error • Undefined class 'AudioBuffer'. • lib/audioplayers_web.dart:21:18 • undefined_class
  error • The name 'AudioBuffer' isn't a type so it can't be used as a type argument. • lib/audioplayers_web.dart:85:15 • non_type_as_type_argument
  error • The name 'AudioBuffer' isn't a type so it can't be used as a type argument. • lib/audioplayers_web.dart:98:10 • non_type_as_type_argument
  error • Undefined class 'AudioBuffer'. • lib/audioplayers_web.dart:105:11 • undefined_class
  error • Undefined class 'AudioBuffer'. • lib/audioplayers_web.dart:116:11 • undefined_class
  hint • The value of the local variable 'isLocal' isn't used. • lib/audioplayers_web.dart:134:22 • unused_local_variable
11 errors and 1 hint found.

Which seems to indicate that the dart:web_audio package does not exist. However if you go to the example folder and run the project on web, it will compile, run and work successfully.

@isoos
Copy link
Collaborator

isoos commented Feb 1, 2020

@luanpotter: This looks looks like a Flutter-internal bug: the Flutter analyzer should recognize the missed libraries. Could you please open a bug in https://github.com/flutter/flutter/issues, copy the details over there, and also reference the bug here? Thank you! (I'll have proper time to do this on Monday if you can't do it until then.)

@isoos
Copy link
Collaborator

isoos commented Feb 3, 2020

@luanpotter: It looks like dart:web_audio is not yet officially supported by Flutter, and there is a discussion on how it should be done in the long term. See: flutter/flutter#49849

@jonasfj
Copy link
Member

jonasfj commented Mar 10, 2020

It's not clear this is a bug in pub.dev

@chipweinberger
Copy link

chipweinberger commented Oct 6, 2023

I'm hitting the same error. I am trying to add Web support to https://github.com/chipweinberger/flutter_pcm_sound

I don't want to use a federated structure if I don't have to.

Can someone upload a example repo with 'dart:web_audio' without a federated repo? Is this even possible?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants