flutter_js icon indicating copy to clipboard operation
flutter_js copied to clipboard

Is it possible to access a js class from another file ?

Open behzad-tmr opened this issue 2 years ago • 2 comments

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()""");

behzad-tmr avatar Feb 07 '23 12:02 behzad-tmr

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.

visign3d avatar Feb 09 '23 15:02 visign3d

I use https://rollupjs.org/

jpolstre avatar May 01 '23 16:05 jpolstre