calculator static method

num calculator(
  1. num operand1,
  2. String operators,
  3. num operand2
)

Implementation

static num calculator(num operand1, String operators, num operand2) {
  try {
    if (operators == '' || operand1.isNaN == true || operand2.isNaN == true) {
      throw Exception('Operator null or error input');
    }
    if (operators == '+') return operand1 + operand2;
    if (operators == '-') return operand1 - operand2;
    if (operators == '/') return operand1 / operand2;
    if (operators == '*') return operand1 * operand2;
  } on Exception catch (exception) {
    print(exception.toString());
  }
  return 0;
}