Flies are attracted to rotting food on top of your compost. To avoid this, mix and bury your food waste within the existing material in your composting system, or add a layer of brown materials such as leaves, shredded paper, or sawdust on top of each layer of food waste.
If the problem persists, leave the lid off for 2-3 hours on a sunny day and then place a layer of wet newspaper on top of the composting materials to create a physical barrier and replace the lid.