I have js code that needs to be translatable to Dart:
(function() {
var s, e;
s = document.createElement("script");
s.src = “//someurl.com/somefile.js";
s.async = true;
e = document.getElementsByTagName("head")[0];
e.insertBefore(s, e.firstChild);
this.OBJECT = this.OBJECT || {};
this.OBJECT.array = this.OBJECT.somearray || [];
})();
OBJECT.somearray.push({
val1 : “foo",
val2 : “bar"
});
Basic part to embed script into head I did like this:
ScriptElement scr = new ScriptElement()
..src = "//someurl.com/somefile.js";
..async = true;
querySelector('head').append(scr);
But I don't know how to correctly check if OBJECT and OBJECT.somearray exists in somefile.js and push an object item in it.
new JsObject(context['Object']), to create an array,new JsObject(context['Array']). There is alsoJsArraywhich might be helpful. I mean, I don't know where exactly you are stuck. If you post what you have tried and which error you get, we might be able to help you better.