What a Fungus Gnat needs:
remove organic material: compost and many bagged soils contain compost. This organic material will often host fungus gnat larva, which live and breed in the compost. By going with a soil-less mix, it may cost a bit more, but often it doesn't contain as many unwanted hitchhikers.
reduce watering: Watering your plants is a chore, but often gardeners overwater their plants, leading to access water. This excess water can lead to many problems like root rot, damping off, but also fungus gnats.
By letting your plants dry out in between waterings, it will greatly reduce the risk of hosting a community of unwanted fungus gnats.
Neem oil: Coming from the neem seed, this oil contains chemicals that are organic, but very useful at controlling the fungus gnats. Neem oil can also be used to control aphids, spider mites, and other pests! By mixing it in with water, and adding a few drops of dish soap allows you to water the soil and drench the soil.
Pyrethrum: Pyrethrum is from the daisy family and actually prohibits the reproduction cycle of the fungus gnat. There are many different organic options that work, but they all work basically the same.
Boiling water: Boiling water will kill fungus gnat larva when poured into bagged soil. Before planting, pour boiling water into the soil to sterilize the mix and rid it of any fungus gnats.
Heat-treating soil: By placing your compost into the oven for 5 minutes at 350, your soil will be sterilized and free of any unwanted fungus, mildew, bacteria, and pests like fungus gnats.
Sand: fungus gnats use a corkcrew-like egg depositing method to bury the seeds. An adult fungus gnat can lay anywhere from 300-500 eggs in a single life cycle! The most simple way to prevent the fungus gnat fro laying eggs is by applying sand to the surface of your seed starts and pots of soil.
All it takes is a layer roughly ¼-½ " thick, we use playground sand, as it is the cheapest option. Almost any hardware store will have it.