The below snippet of code gives me error in dartpad. But the same code works fine in the course which I am doing online. I am using dart version 2.8.4.

void main() {

 int var = operation(5,5,add);  --> Error


// class calculator {

//   calculator({this.operand});

// }

int add(int n1, int n2) {
  return n1+n2;

int multiply(int n1, int n2) {
  return n1*n2;

int operation(int n1, int n2, Function operand){
  return operand(n1, n2);


Error compiling to JavaScript:
Error: Expected ';' after this.
 int var = operation(5,5,add);
Error: Expected an identifier, but got '='.
 int var = operation(5,5,add);
Error: Compilation failed.

Solution 1: Peter Haddad

int var = operation(5,5,add); don't use var as a variable name, it a keyword used in the dartlang, just change the name to anything else and you wont get any error:

int operationResult = operation(5,5,add);