Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I execute Dynamically (like Eval) in Dart? #36989

Closed
smile2014 opened this issue May 17, 2019 · 2 comments
Closed

How do I execute Dynamically (like Eval) in Dart? #36989

smile2014 opened this issue May 17, 2019 · 2 comments

Comments

@smile2014
Copy link

@smile2014 smile2014 commented May 17, 2019

var doAdd = new Function("iNum", "alert(iNum + 10)");
doAdd(10);----> 20

@lrhn
Copy link
Member

@lrhn lrhn commented May 17, 2019

Dart does not allow you to create code at run-time.

What problem are you trying to solve?

There are workarounds when you are running on the VM and has access to isolates. You can create a new library with a main function, encode the source code as a data: URI and spawn it as a new isolate, but that will not allow you to create a new functions in the current isolate. You'll have to communicate with the new code using isolate port communication.

In general, I'd recommend trying something else. It is often possible to get the effect of generating code by just combining first-class function values, but that obviously depends on the problem at hand.

Loading

@smile2014
Copy link
Author

@smile2014 smile2014 commented May 19, 2019

I dynamically render the form through the json data given by the backend. The disabled corresponds to a piece of javascript, similar to angular ngx-formly expression

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants