Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

Error: @staticInterop classes should not contain any generative constructors. Use factory constructors instead. #13

Open
Leramir1 opened this issue Jun 29, 2023 · 0 comments

Comments

@Leramir1
Copy link

When building this app locally on latest flutter version. I ran into an issue with audio

../../../../AppData/Local/Pub/Cache/hosted/pub.dev/audioplayers_web-2.1.0/lib/web_audio_js.dart:8:12: Error: `@staticInterop` classes should
not contain any generative constructors.
Use factory constructors instead.
  external JsAudioContext();

I resolve it by modifying the code it's and implementing factory constructors.

import 'dart:html';
import 'package:js/js.dart';

@JS('AudioContext')
@staticInterop
class JsAudioContext {
  external factory JsAudioContext();
}

extension JsAudioContextExtension on JsAudioContext {
  external MediaElementAudioSourceNode createMediaElementSource(
    AudioElement element,
  );

  external StereoPannerNode createStereoPanner();

  external AudioNode get destination;
}

@JS()
@staticInterop
abstract class AudioNode {
  external factory AudioNode();
}

extension AudioNodeExtension on AudioNode {
  external AudioNode connect(AudioNode audioNode);
}

@JS()
@staticInterop
class AudioParam {
  external factory AudioParam();
}

extension AudioParamExtension on AudioParam {
  external num get value;
  external set value(num value);
}

@JS()
@staticInterop
class StereoPannerNode implements AudioNode {
  external factory StereoPannerNode();
}

extension StereoPannerNodeExtension on StereoPannerNode {
  external AudioParam get pan;
}

@JS()
@staticInterop
class MediaElementAudioSourceNode implements AudioNode {
  external factory MediaElementAudioSourceNode();
}

Although this resolved my issue, and I could hear the audio, I don't believe modifying a file in AppData should be the solution. Any idea on what the actual solution should be? I'm new to using Flutter.

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

No branches or pull requests

1 participant