I have a map like:
Map<Coordinates, Offset> myMap = {someCoordinates: someOffset, ...};
And i want to get an offset by coordinates (where coordinates is a simple class with int x and int y)
...
Offset someOffset = myMap[someCoordinaets];
but it returns null. What i'm doing wrong? Can i use an object in the map key?
EDIT here is my Coordinates class
class Coordinates {
final int col;
final int row;
Coordinates(this.col, this.row);
int getCol() {
return col;
}
int getRow() {
return row;
}
}
Solution:
import 'package:quiver/core.dart';
class Coordinates {
final int col;
final int row;
Coordinates(this.col, this.row);
// solution
bool operator ==(o) => o is Coordinates && col == o.col && row == o.row;
int get hashCode => hash2(col.hashCode, row.hashCode);
int getCol() {
return col;
}
int getRow() {
return row;
}
}