Say I have:
Function(int x, int y) func = (int x, int y) {
return (1, 2); // error
};
How to actually return (1, 2) from above function?
Methods in Dart can only return one value. So if you need to return multiple values you need to pack them inside another object which could e.g. be your own defined class, a list, a map or something else.
In your case with x and y you could consider using the Point class from dart:math:
import 'dart:math';
Point<int> func(int x, int y) => Point(x, y);
Support for returning multiple values in Dart are a ongoing discussion here: https://github.com/dart-lang/language/issues/68
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With