The evolution of the dust and gas content in galaxies