How to not lose focus after each disruption in flow
A very simple solution, that might work, and is worth a try. When you reach such a block, jot a note to yourself that captures the problem or the crux. Then get up from your desk and take a ten minute or so walk. Get your blood moving a bit and break the flow explicitly. Take the note and a pencil/pen, so that you can write ideas that might occur. 

You may find that the solution will come to you, but at least, the break may help to clear your mind of the reason you may be pursuing the wrong solution. 

This won't work for everyone, of course, but it is a painless way to experiment. 

Oh, and don't be checking your phone on the walk or texting, or ... It might even be best to leave it behind since you will only be away for a few minutes.