You are probably dealing with soil gnats, which feed on organic soil matter and often find their way into packaged potting soils. They can often be killed by pouring soapy water into the soil and leaving it for a few minutes before rinsing with plain water.
There is a good probability the the little flies on your plants are aphids. Aphids come in multiple varieties and colors. They are harmful to your plants and ugly to look at, Some people buy lady bug beetles for their gardens to consume aphids.