  Ultralight dark matter (ULDM) is proposed as a theoretical candidate of dark
matter particles with masses of approximately $10^{-22}$ eV. The interactions
between ULDM particles and standard model particles would cause variations in
pulse arrival times of millisecond pulsars, which means that the pulsar timing
array (PTA) can be used to indirectly detect ULDM. In this letter, we use the
gamma-ray PTA composed of 29 millisecond pulsars observed by the Fermi Large
Area Telescope (Fermi-LAT) to test four ULDM effects, including gravitational
effects for generalized ULDM with different Spin-0/1, the fifth-force coupling
effect of dark photon, and the modified gravitational effect of the Spin-2
ULDM. The gamma-ray pulsar timing is not affected by the ionized interstellar
medium and suffers relatively simple noises, unlike that of the radio band. Our
work is the first time that the gamma-ray PTA has been used to search for the
ULDM. No significant signals of ULDM are found based on the Fermi-LAT PTA for
all four kinds of ULDM models. Constraints on ULDM parameters are set with the
95% confidence level, which provides a complementary check of the nondetection
of ULDM for radio PTAs and direct detection experiments.
