Closed matanlurey closed 1 year ago
@nshahan, this seems like a similar issue to the one filed in #49693, but the Missing canonical name
error is slightly different.
Is it possible to try a later dev version? There were a couple changes that have landed since then (I think 2.19.0-52.0.dev was the last of them). You'll still come across factory
issues, but it'll be a different error so we can de-dup. :)
FYI - I hope to tackle the factory
issue soon (and static methods, which I'm surprised worked for you).
Is it possible to try a later dev version? There were a couple changes that have landed since then (I think 2.19.0-52.0.dev was the last of them). You'll still come across
factory
issues, but it'll be a different error so we can de-dup. :)
It's not trivial for me to change versions right now in the middle of a project, but I can upload what I have so far shortly.
FYI - I hope to tackle the
factory
issue soon (and static methods, which I'm surprised worked for you).
Just to confirm - static methods allow compilation, but didn't work. I ended up doing:
/// Methods provided to [WebGLRenderingContext] using [staticInterop].
///
/// See https://pub.dev/packages/js#interop-with-native-types-using-staticinterop.
extension WebGLRenderingContext$ on WebGLRenderingContext {
/// Creates a [WebGLRenderingContext] via [HTMLCanvasElement$.getContext].
static WebGLRenderingContext fromCanvas(
HTMLCanvasElement canvas, {
bool? alpha,
bool? antialias,
}) {
final context = canvas.getContext(
'webgl',
_WebGLGetContextAttributes(alpha: alpha, antialias: antialias),
);
if (context == null) {
throw UnsupportedError('WebGL not supported');
}
return context as WebGLRenderingContext;
}
}
Okay, I figured static methods wouldn't work, so that's consistent. Yeah, that's a fine alternative (although migration to views in the future will be a teeny bit annoying). I believe @joshualitt has used top-level methods as well to work around these factories.
Top-level methods work fine but then I'm expanding the top-level API surface instead of stuff living "naturally" :)
Is there plans for non-external
factory constructors and static methods to be supported, either now or post views?
(At minimum I'd hope this was a static error, not a crash)
Is there plans for non-external factory constructors and static methods to be supported, either now or post views?
Yes, definitely. These work as expected in dart2js, and it's one of my goals for Q3-ish to add support for this in @staticInterop
for DDC. With views, we should get both for free by virtue of it being a language feature.
This was added late last year, but I never closed this issue. You should be able to use non-external factory
and static
methods on @staticInterop
types for all web compilers. You can also write these members using extension types.
Minimal reproduction:
With
Dart SDK version: 2.17.6
,webdev serve
crashes:I changed it from a
factory
constructor to astatic
method and it compiles/works as expected.