I am creating a linear equations solver app in flutter with step-by-step procedures. To aid me, I searched on google and found some sample code. However, this was in java so I used an online java to dart converter. Since doing this, I've been running into a lot of problems because it doesn't seem like the website is up to date.
This is the website: http://sma.github.io/stuff/java2dartweb/java2dartweb.html
The converted code is used to expand the linear equation given. Below is the converted code:
List<String> expand(String expression)
{
List<String> expr = expression.split("[(]");
int multiplier = (((expr[0] == "-") || (expr[0] == " ")) ? Integer.parseInt(expr[0] "1") : Integer.parseInt(expr[0]));
List result = [];
List<String> exprInBracket = split(getExprInBracket(expr[1]));
for (int i = 0; i < exprInBracket.size(); i ) {
String elem = exprInBracket.get(i);
try {
Integer constant = (multiplier * Integer_.parseInt(elem));
result.add(constant.toString());
} on Exception catch (e) {
Integer newCoefficient = (getCoefficient(elem) * multiplier);
Log.d("VARIABLE", variable);
result.add(newCoefficient.toString() variable);
}
}
return result;
}
These are the errors that I am facing:
Undefined name 'Integer'. Try correcting the name to one that is defined, or defining the name.
The method 'size' isn't defined for the type 'List'. Try correcting the name to the name of an existing method, or defining a method named 'size'
The method 'get' isn't defined for the type 'List'. Try correcting the name to the name of an existing method, or defining a method named 'get'.
The method 'getCoefficient' isn't defined for the type 'MainApp'. Try correcting the name to the name of an existing method, or defining a method named 'getCoefficient'.
Undefined name 'Log'. Try correcting the name to one that is defined, or defining the name.
Undefined name 'variable'. Try correcting the name to one that is defined, or defining the name.
A value of type 'List<dynamic>' can't be returned from the method 'expand' because it has a return type of 'List<String>'
CodePudding user response:
I converted your example from Java
code to Dart
but your example missed:
- split function
- getExprInBracket function
- getCoefficient function
- variable variable
Below your converted code:
List<String> expand(String expression)
{
List<String> expr = expression.split("[(]");
int multiplier = (((expr[0] == "-") || (expr[0] == " ")) ? int.parse(expr[0] "1") : int.parse(expr[0]));
List<String> result = [];
List<String> exprInBracket = split(getExprInBracket(expr[1]));
for (int i = 0; i < exprInBracket.length; i ) {
String elem = exprInBracket[i];
try {
final constant = (multiplier * int.parse(elem));
result.add(constant.toString());
} on Exception catch (e) {
int newCoefficient = (getCoefficient(elem) * multiplier);
result.add(newCoefficient.toString() variable);
}
}
return result;
}