Skip to content Skip to sidebar Skip to footer

Get Variable From Javascript Into Dart

I have a JavaScript library being imported in my HTML Documents head. How can I access objects from this library? Thank you.

Solution 1:

The interop with JavaScript is desribed in article 'Using JavaScript from Dart: The js Library'

In short, you have to:

//import the JS interop libimport'package:js/js.dart' as js;

// access the JS context for the pagevarcontext= js.context;

// then use context to access JS objectvarcanvas= query('#map_canvas');
vargooglemaps= js.context.google.maps;

// and create JS objects accessed through proxiesvargooglemap=newjs.Proxy(googlemaps.Map, canvas);

For more details (scopes, lifetimes, callbacks, etc) and examples, refer to linked article.

Post a Comment for "Get Variable From Javascript Into Dart"