There's no right way to do it - Florence first or Florence later. But, if you go to Florence first then to the Cinque Terre, you would have the option of going on to Venice via Milan. You could even do that with only one train connection if you start in Monterosso (or Levanto) because the fast trains stop there. The route via Milan might take a little longer but might require fewer changes). Even if you stay in another town besides Monterosso or Levanto, you would just need to take one of the Cinque Terre Express regional trains to connect to a Milan train and on to Venice.
There are a lot of regional trains up and down the riviera. If the connection from say Vernazza or another smaller CT town seems too tight, just buy separate tickets: buy a ticket from say Levanto to Venice and a separate regional ticket from the town you are staying in to Levanto, so you can give yourself a longer connection time of need be. You could do the same if connecting in La Spezia on to Florence + Venice.
One other consideration might be cruise ship visits in the Cinque Terre during that time. There are sites (don't ask me where, but you can find them) that show which days might have cruise ships docked at La Spezia so you could assume those days would be the busiest days in the Cinque Terre. (But in July, it's likely to be a zoo no matter which day you visit.) In other words, you can choose the order of Florence and Cinque Terre and one gets you there on days with fewer cruise ships, that might be a little better for you. Maybe.