Apparently cut down on the watering because Gnats love wet soil. Try some very tiny stones, grit on top of the soil. I had some and they come in from the back garden via the window vent. They run round the window and I catch them with the very thing they love...water...end. Also fruit flies are a pest so hide any fruit or cover with a cake cover.
I've had this problem in the past and the only thing that works for me was to clean the roots and pot and put fresh soil. I just repotted a plant with fresh soil and I'm starting to see Gnats again. I'm thinking I want to try the peroxide mixture because none of the others mentioned worked well for me. My problem is it's a cactus and I don't want to drown it. Any thoughts on how much I can use to be effective but not drown my plant?
I found this on H/Peroxide treatment. Mix one part 3% hydrogen peroxide with four parts water. Allow the top layer of your soil to dry, and then water your plants with this solution as you normally would. The soil will fizz for a few minutes after application; this is normal. The fungus gnat larvae will die on contact with the hydrogen peroxide. After a few minutes the fizzing stops and the peroxide breaks down into harmless oxygen and water molecules. Repeat as needed. http://www.smallfootprintfamily.com/controlling-fungus-gnats-organically K
Wow, This was started along time ago. If you can't get rid of fungus gnats, go out and buy a dog flee collar. Put your plant in a zip lock bag with the flee collar around the top part of the pot. Then close it. So your plant is in plastic greenhouse. You can open it every day for a minute but close it quickly. Keep it that way for a few weeks and all the larvae will hatch and die and end the cycle. These bugs live on moist decomposing organic material. Let most plants dry out once in a while.