I have 4 available sources of attack on Gnats.
I add Food Grade Diatomaceous Earth pre planting to the entire mix. (1/8 c/g And then as an as needed topdress deterrent(and as a mineral supplement) thereafter. Adding about 1/8-1/4 per 5 gallon pot, mixing a portion into the soil, and dusting over the rest. It is effective wet or dry, but least effective when wet.
Tip:
I like to ammend the soil with it, just before stretch..
Other methods I have on hand are Pot Poppers Nematodes, Mosquito Bits, and Neem Pellets. I'll try an not say it too loud.....

But the combination of methods have worked well as I've not seen a fly for 2-3 years....
Thanks for stopping by!