ChessPiece.fromJson constructor
ChessPiece.fromJson(
- dynamic json
Either String or Map<String, dynamic>
Implementation
factory ChessPiece.fromJson(dynamic json) {
assert(json != null, 'JSON cannot be null');
assert(
json is String || json is Map<String, dynamic>,
'Invalid JSON format for ChessPiece',
);
json = (json is String ? jsonDecode(json) : json) as Map<String, dynamic>;
assert(
json['type'] != null && json['color'] != null,
'type or color cannot be null in JSON format for ChessPiece',
);
return ChessPiece(
type: PieceType.values.byName(json['type']),
color: PieceColor.values.byName(json['color']),
);
}