I got this.
Fans. Get a good flow of air across the top of your soil. If you are in plastic, you also need to flow some air at those holes. If in fabric, just the tops should do you unless you have nasty bags. Make sure any drip tray you might have is dry and the bottoms of whatever container you use are not flat on the ground.
Since they are fungus gnats, they are flying to and for the fungus in your soil. If they cannot get to that fungus, they have no interest in being there. If you keep a good flow of air going across your soil, the gnats cannot readily do their thing. I'm going to give you a personal guarantee that sufficient air circulation across any exposed soil will keep any flying and most crawling insects out of your soil. I don't know what to back that guarantee up with, so I'll call it an unbonded guarantee.
In the future, mix in diatomaceous earth with your soil before you plant. That also helps.
Now, someone is going to tell you how to treat with DE mid-grow and yellow sticky paper. Take it away.