Questions tagged [dart-js-interop]

Dart js-interop packages provides access to the Javascript objects.

Dart js-interop packages provides access to Javascript objects in the browser to use legacy JavaScript code in you Dart application. The library works both in Dartium and in Dart code compiled to JavaScript (with Dart2Js).

175 questions
14
votes
3 answers

Expose Dart functions to javascript

I'm a bit of a newb to dart, and trying to get my feet wet by writing some library functions in it. While I've had no problem calling javascript functions from dart, I'd love to be able to call dart functions from javascript, but so far, I'm not…
Mason Bryant
  • 1,372
  • 14
  • 23
11
votes
2 answers

What is a difference between dart:js and js package?

Everywhere in Dart documentation it is recommended to use js package for javascript interoperability. However, I have recently found that dart:js package exists in SDK that seems to have similar (but not same) interface. Are there any differences…
Samuel Hapak
  • 6,950
  • 3
  • 35
  • 58
9
votes
3 answers

How to call a jQuery function from Dart?

This is a typical situation in jQuery: $(".myClass").myFunction({ aKey: 'some value' }); How do you call that using dart:js? The documentation is a bit cryptic and a similar question that I found here seems dated.
alearg
  • 685
  • 7
  • 17
8
votes
2 answers

Using dart to create a javascript library

The problem I'm currently working on a JavaScript library, and in order to reduce the amount of bugs I thought that my library might benefit from using Dart's static typing mechanism. First, because my lib wasn't doing any interop neither with HTML…
Lu4
  • 14,873
  • 15
  • 79
  • 132
7
votes
1 answer

dart:js error when calling promiseToFuture - NoSuchMethodError: tried to call a non-function, such as null: 'jsPromise.then'

I'm trying to await a custom global JavaScript function: var promise = js.context.callMethod('performAuthenticationInNewWindow', [uri.toString()]); print(promise); var qs = await promiseToFuture(promise); Which prints the following: [object…
sroes
  • 14,663
  • 1
  • 53
  • 72
7
votes
2 answers

How do I create a global (on the window) object in Dart lang?

Let's say I want to create a global object called Hello and add the function world on that object, so that any other JavaScript library in the browser can simply call it with window.Hello.world(); How do I create such an object in Dart lang and how…
corgrath
  • 11,673
  • 15
  • 68
  • 99
7
votes
1 answer

Is there a better way to make a method of a Dart class callable from JS with the new js 0.6.0 package?

index.html (head) index.dart import 'package:js/js.dart'; @Js() // about to being changed to @JS external String callDartMethod(p); main() { …
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
6
votes
1 answer

Use js library in flutter web

I need widget with bpmn.js view: https://github.com/bpmn-io/bpmn-js Used HtmlElementView: // ignore: undefined_prefixed_name ui.platformViewRegistry .registerViewFactory('bpmn_view', (int viewId) => element); return Column( …
6
votes
1 answer

How to call a JavaScript function named `call` from dart

Is there any way to call a JavaScript function named call() (in a nested object) from Dart or do I have to wait for Dart 2.0 from which the special handling of call() might get removed? I have a JS Proxy like: @JS() class SomethingFancy { external…
Dennis Kaselow
  • 4,351
  • 1
  • 19
  • 18
6
votes
2 answers

Automate JavaScript Interop in Dart

When using a third-party JavaScript library in my Dart project, I manually go through the library's documentation and iterate through its properties and methods to build the Dart code through a series of tedious context and callMethod calls. Has…
Damon
  • 826
  • 1
  • 10
  • 25
6
votes
1 answer

How do I access `this` from JavaScript via JS - Dart interop?

I need to access a JavaScript object's this from a Dart function. I'm effectively adding a new method to a JavaScript object, via Dart-JS interop. I need to access properties that are on the JavaScript object from the method defined in Dart.
Seth Ladd
  • 112,095
  • 66
  • 196
  • 279
5
votes
1 answer

How to pass options to javascript function using dart:js?

I have the following functional javascript code to demonstrate what I want to achieve. It should output the object passed to the method, and then the value of the property "a".