flutter_js
flutter_js copied to clipboard
Is it possible to access a js class from another file ?
I have to communicate with a js code with lots of files and classes . the problem is that when I run runtime.evaluate("""${jsFile}myFunction()"""); the other classes can not be imported . following is a simple example that what i need to do .
lets have two js files like following in the flutter assets folder . first file : ClassOne.js
class ClassOne { constructor() { this.id = 1; }
sayHi() {
console.log(`Hello from ${this.constructor.name} with ID: ${this.id}`);
}
}
and second file : ClassTwo.js
function myFunction( ) { let j = new ClassTwo(); j.sayHi(); return 0 ; }
class ClassTwo extends ClassOne{ constructor() { super(); this.id = 2; }
sayHi() {
console.log(`Hello from ${this.constructor.name} with ID: ${this.id}`);
}
}
Is it possible to import the first class in second one . ) runtime.evaluate("""${jsFile}myFunction()""");
you can try minify all your classes in one single file and copy/paste the code at the start of your file. then write some logic for interop.
I use https://rollupjs.org/