ChessPiece.fromJson constructor

ChessPiece.fromJson(
  1. dynamic json
)

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']),
  );
}