I have the following class in dart...
class Color {
final int value;
const Color._internal(this.value);
static const Color WHITE = const Color._internal(0);
static const Color BLACK = const Color._internal(1);
int get hashCode => value;
String toString() => (this == WHITE) ? 'w' : 'b';
}
When I run the flutter analyze command I get the following error...
info • Override
==if overridinghashCode• lib/chess.dart:1584:13 • hash_and_equals
As a test I added the method
bool operator==(Object o) => true;
But then I got another analyzer problem....
error • The constant map entry key expression type 'Color' can't override the == operator • lib/chess.dart:44:3 • const_map_key_expression_type_implements_equals
This is because the Color object is used as a key in a static const map...
static const Map<Color, List> PAWN_OFFSETS = const {
BLACK: const [16, 32, 17, 15],
WHITE: const [-16, -32, -17, -15]
};
So I am confused as to what my options are to prevent these analyzer issues.
If I remove the hashCode, the class wont work in a map... If I add the == operator I just get a different error.
What is the best option?