Skip to main content

Dart Function

Dart function is object that accepts both positional and named parameters.

Named Parameters

You can mix positional and named parameters in dart.

int calc(String op, {required int a, required int b}) {
return switch (op) {
"sum" => a + b,
"mut" => a * b,
_ => throw Exception('Unknown op ' + op)
};
}

void main() {
print(calc("sum", a: 1, b: 2));
print(calc("mut", a: 2, b: 3));
}

References