-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
area-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.web-js-interopIssues that impact all js interopIssues that impact all js interop
Description
Hey. I have a build of Chromium with a custom Sensor object, and I'm trying to bind to it. The Sensor is similar to this one found in html_dart2js.dart:
@Native("Accelerometer")
class Accelerometer extends Sensor {
// To suppress missing implicit constructor warnings.
factory Accelerometer._() {
throw new UnsupportedError("Not supported");
}
factory Accelerometer([Map? sensorOptions]) {
if (sensorOptions != null) {
var sensorOptions_1 = convertDartToNative_Dictionary(sensorOptions);
return Accelerometer._create_1(sensorOptions_1);
}
return Accelerometer._create_2();
}
static Accelerometer _create_1(sensorOptions) =>
JS('Accelerometer', 'new Accelerometer(#)', sensorOptions);
static Accelerometer _create_2() =>
JS('Accelerometer', 'new Accelerometer()');
num? get x native;
num? get y native;
num? get z native;
}
However, the above is using some internal APIs, and I can't seem to get past setting sensorOptions on my version.
@JS()
extension type CustomSensor._(JSObject _) implements JSObject {
external CustomSensor(SensorOptions sensorOptions);
external void start();
external void stop();
external num get myValue;
external void addEventListener(String type, JSFunction? callback, [JSAny options]);
}
@JS()
@anonymous
extension type SensorOptions._(JSObject _) implements JSObject {
external factory SensorOptions({num frequency});
external num get frequency;
}
The errors complain about the constructor. SensorOptions is supposed to be like a JS dictionary object, so that's why I was trying @anonymous. Any ideas?
Metadata
Metadata
Assignees
Labels
area-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.web-js-interopIssues that impact all js interopIssues that impact all js interop