Can anyone please help me? I don’t understand why my code is giving an error.
int add (int n1, int n2){
n1 + n2;
}
void main() {
int step1Result = add(n1: 5, n2: 9);
print(step1Result);
}
>Solution :
You’ve crated positioned constructor but passing data as named constructor.
try like
int step1Result = add( 5, 9);
Or to create positioned constructor
int add({required int n1, required int n2}) {
return n1 + n2;
}
void main() {
int step1Result = add(n1: 5, n2: 9);
print(step1Result);
}
Check more about using-constructors