Skip to content
This repository was archived by the owner on Jun 5, 2024. It is now read-only.
This repository was 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

@Leramir1

Description

@Leramir1

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions