Also, I am going to say this right now. If you are using GOOD soil, if your soil is HEALTHY and LIVING and good for your plants, chances are really high you WILL get fungus gnats. Fungus gnats have been the bane of many indoor cannabis gardeners. What others have mentioned helps a lot. First though remember a few things about them.
1) Fungus Gnats like "living hot <heavy with organic compounds like guano, worm casings, kelp, fish meal, etc> the MORE "organic" the better they like it! (You won't find many fungus gnats in Miracle Grow! There is a reason for that.).
2) Adult Fungus gnats have NO mouth bits. They do NOT eat, their larvae do. Fungus Gnats are like cicadas... The adults just breed (2000 eggs per 1 female) the larvae tunnel down into the plants root system and live among the root hairs until they are old enough to breed and mate.
3) There are ALWAYS fungus Gnats present everywhere. Period. If you do nothing, at all...You can be overwhelmed within a week and have thousands of the bastards. They are most deadly to seedlings and newly vegetating plants.
4) Best methods to fight them. Mosquito dunks or chips >
https://www.amazon.com/SUMMIT-CHEMI...001LE1VC/ref=pd_lpo_3?pd_rd_i=B0001AUF8G&th=1 this is what I use. I add them to my teas and water 2 x a week with this.
5) I use one of these in each grow tent...
Katchy UV Mosquito/Gnat catcher
Ever since I have used these, along with the chip and the yellow sticky traps, I have not have a problem since. The bastards are THERE, they just cause no more problems. The first week I set up the gnat trappers they sucked up thousands of the adult buggers never allowing them to breed, I LOVE it! and my crops have been fine ever since.
Best of luck! :D

Warmly,
Jackie