Gnats are a PITA so not getting them is the best method. Get some yellow and blue sticky traps if you can find the blue ones and hang some on the walls and keep a couple in the pots so you know as soon as some show up. If you catch any then make sure you have one trap in each pot too. I cover the top of the soil with diatomaceous earth and water from the bottom to keep the surface of the DE dry and unbroken if I get them.
They are often in bags of potting soil so I test any new bags when I first use them or if they have been open for any length of time. Take a sample, tsp, in a shot glass. Fill to the top with water then use a piece of paper towel or toilet paper to lay on top and pick up anything floating on the surface and check out what's there with a strong magnifying glass or scope. I use an old 30X scope from Radio Shack. Look for tiny, clear larvae with two tiny black dots for eyes. Those be baby gnats. The adults don't damage the plants as they just mate then lay eggs in the damp soil and die. The larvae eat the fine root hairs and stop the plant's growth and will eventually kill the plant as it can't draw up water once all the root hairs are gone.
Still not as bad as mites.
If you've been out working in the yard don't visit your plants until you've at least changed clothes especially shoes and socks as bugs from the lawn are likely all over those.
Good luck!