-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[js interop] Classes inside namespaces on the window cannot be constructed #54531
Comments
Thanks for filling the issue and reaching out. We define final JSObject? multiFormatReader = getProperty(globalThis, 'ZXing.BrowserMultiFormatReader'); I don't believe the API supports using final JSObject? miltiFormatReader = getProperty(zxing, 'BrowserMultiFormatReader'); Will give you an actual object instead. Does that work for you? If so, it's possible the |
Thanks for clarifying the difference with However, I didn't quite get the results of what I was expecting still.
Maybe also important to mention for context is that the older version (which I am trying to update away from dart:html/package:js) was defined like this:
Back then this was allowed it seems. |
Thanks for all the additional input. I believe this is likely related to another issue we saw recently in the compiler. I just filed an issue with more details here: #54534 I still need to double check and test this locally, but it is likely that the new interop constructor is triggering the issue with the precedence of the |
@sigmundch as the main bug has been fixed now, shall we close this one as well, or do you want me to independently verify the fix? (although I think we now have a test in the SDK that covers this pattern, which would make my point moot?) |
Thanks for following up! Yes! I've started the cherry-pick process to make sure this is included in the next stable release of Dart and Flutter. Please do keep us posted if you still run into trouble |
Will do! |
@sigmundch So it seems to be working at HEAD now, thanks! I tested it with the following sample, and it is WAI: import 'dart:js_interop';
import 'dart:js_util';
void main() {
final zxing = getProperty(globalThis, 'ZXing');
final browserMultiFormatReaderConstructor = getProperty(zxing, 'BrowserMultiFormatReader');
final browserMultiFormatReader = callConstructor(browserMultiFormatReaderConstructor, const []);
print('instance is correct type: ${instanceof(browserMultiFormatReader, browserMultiFormatReaderConstructor)}');
// This is false, because the dot notation is not supported by the tooling.
print('instance is correct type: ${instanceOfString(browserMultiFormatReader, 'ZXing.BrowserMultiFormatReader')}');
print(getProperty(browserMultiFormatReader, 'isMediaDevicesSuported')); // true
} Should I file a bug for supporting the dot notation in the |
whohoo 🎉 🎉 ! thank you so much for verifying and keeping us posted! |
I was updating a JS interop part of a library and encountered that
globalThis
did not contain a property which should have pointed to a JS class.The library that I am integrating is ZXing, a barcode scanning library, which supports the web.
To reproduce:
flutter create web_sample --platforms=web
lib/interop.dart
lib/interop.dart
main.dart
flutter run -d chrome
This outputs
It seems that the
globalThis
in Dart, is not fully in sync with the browser equivalent?I have also tried using the
callAsConstructor<T>()
utility, where I hadZXing
as a separate interop type,which had
BrowserMultiFormatReader
as a JSFunction, but that ended up with the same result. (probably because that also looks atglobalThis
)dart info
MacOS Sonoma 14.1.2
Google Chrome 120.0.6099.199 (Official Build) (x86_64)
Flutter 3.16.5 / Dart 3.2.3
The text was updated successfully, but these errors were encountered: