Maggots will be attracted to your trash can’s stinky smells and food residue. So between trash collection days, give your trash can a good clean. This is especially vital if the food has leaked or there are juices at the bottom of the trash can.
You can also put some basil in the bottom of your trash can because bugs hate basil (source).