Is there any way to convert String into Dart functional code?

Viewed 542

I'm getting conditions in an string.

For example: String conditions = "gender == 1 && gender == 3";

I want to convert it into If Conditional statement.

like if(gender == 1 && gender == 3) { }

How can I parse that string ?

1 Answers

You can use function_tree package to convert string to expression.

String conditions = "gender == 1 && gender == 3";
if(conditions.interpret()) {  }
Related