Decaying veg attracts fruit flies, they lay eggs, eggs hatch maggots, they become fruit flies. Decaying veg becomes compost, flies lose interest, OK for use.
Are you talking about a compost bin in a corner of your garden where vegetable waste, grass mowings and shredded paper etc is rotting down, or are you talking about the little bin you keep in or near your kitchen to put potato peelings, cabbage leaves and tea leaves in?
I leave my little bin outside in summer, don't want those flies in the kitchen. Needs emptying on compost heap more often and washing out.
Try to keep the lid tight down, put a brick on it, to keep the flies out. Makesure you only put uncooked vegetable matter in there and empty it often. Ours gets emptied every day. I know that might not be possible for you but in warm weather it does need to be done frequently, and then washing it out afterwards. That way the only flies you should get in there will be fruit flies. Their larvae are hardly noticeable.
The problem should disappear as the temperatures drop.
How about taking up fishing
My dalek-style compost bin seems to have more animal matter than vegetation at the moment. There are not only worms but hundreds of woodlice as well as fruit flies and some sort of flying ants. I.don't know how they all get in there, as it's sitting on gravel, but I suppose they all help to process the compost, and then when they die they enrich it. I take the lid off from time to time, to allow the winged creatures to fly off.
Wondering if you put bread stuff in bin. Best not to and that would give you big maggots.
I wish I'd known about all the creepy crawlies that contribute to making compost, before I'd started. I'm a big animal and insect lover so never kill anything (even daddy long legs get politely and gently escorted off the premises if one gets in an open window)....however I'm a bit, well, scared of things that wiggle, move quickly, and look like they are miniatures from a horror film! I know that they are probably more scared of me than I am of them, and they are harmless, and that some are essential for compost, but they just freak me out! The last time I tried to shovel compost out from the bottom a little newt came trotting out. I think they heard my scream in the space station! Ridiculous I know. I'm going to try and grow a pair otherwise I'll never make use of the lovely compost that's forming!