Best way to deal with flatworms is to deal with them as soon as you see them.
I have treated my tank many times with flatworm exit and have never lost any fish.
Flatworm exit is completely safe, it is the flatworms that cause problems when they died, it is a very good idea to maybe remove corals and dip them in freshwater for 1 min and then put them back and treat the tank.
before treating the tank turn your sump off, take out 20% water from the tank and have the water that you removed ready to put back after 20 mins, also add carbon after 20 mins, turn on sump
Retreat tank in a few days. And maybe again in a week however you don’t need to change water or add carbon this time as you should not have any. The treatment is just to make sure.
It you have flatworms it is normally a sign of high nutrients.