The thing people seem to ignore in discussions about fungus gnats is the actual soil. I've only had a gnat problems when I used potting soil with peat moss in it. I don't get gnats in "palm/cactus" soil, or when I use soil dug out of my garden.
From what I've seen, if I use a soil that gnats are attracted to, I'll probably get gnats. If I use soil that doesn't provide their preferred environment, I won't.