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
//print(operation(5,5,add));
}
// 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:
Error compiling to JavaScript:
main.dart:3:2:
Error: Expected ';' after this.
int var = operation(5,5,add);
^^^
main.dart:3:10:
Error: Expected an identifier, but got '='.
int var = operation(5,5,add);
^
Error: Compilation failed.